★ WELCOME ★

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
articles:linux:docker-reference-page [2022/02/12 15:42]
tom [Docker Compose]
articles:linux:docker-reference-page [2022/02/12 16:32] (current)
tom [Packaging & Distributing Your Own Docker Containers into Images]
Line 64: Line 64:
 # To enter into a terminal of a running container # To enter into a terminal of a running container
 docker exec -it [container name or last 12 positions of container id] /bin/bash docker exec -it [container name or last 12 positions of container id] /bin/bash
 +
 +# To list Docker networks:
 +docker network ls
  
 </code> </code>
Line 84: Line 87:
     ports:     ports:
       - [host port]:[container application port]       - [host port]:[container application port]
 +    volumes:
 +      - [user reference name]:[container path] {for a "named" volume}; or
 +      - [host path]:[container path] {for a "defined" volume}; or
 +      - [container path] {for an anonymous volume}
     environment:     environment:
       - [environment setting]=[assigned value]       - [environment setting]=[assigned value]
Line 90: Line 97:
     ports:     ports:
       - [host port]:[container application port]       - [host port]:[container application port]
 +    volumes:
 +      - [user reference name]:[container path] {for a "named" volume}; or
 +      - [host path]:[container path] {for a "defined" volume}; or
 +      - [container path] {for an anonymous volume}
     environment:     environment:
       - [environment setting]=[assigned value]        - [environment setting]=[assigned value] 
 +
 +# For two containers to share a volume, you can set that after defining named volumes above and adding the volume after the container definition and using an already defined name (i.e).
 +
 +volumes:
 +  db-data: {assuming db-data was established above}
 +    driver: local {this is needed but not sure why}
 +
 </code> </code>
  
Line 104: Line 122:
 Commands: Commands:
  
-up = start a Docker Compose configuration +  up = start a Docker Compose configuration 
-down = stop a Docker Compose configuration+  down = stop a Docker Compose configuration
  
 Examples: Examples:
Line 113: Line 131:
 </code> </code>
  
-===== Docker Volumes =====+===== Persistent Data with Docker Volumes =====
    
-Persistent data between container restarts.+You need to do this when you want to store data/files between restarts of a Docker container
  
 +You have three types of Docker volumes, i.e.
  
 +<code>
 +# A defined volume (Note: I am only showing the -v flag).
 +docker run -v [host folder]:[container folder]
 +docker run -v /home/myvolume/data:/var/lib/mysql/data
 +
 +# An anonymous volume (Note: I am only showing the -v flag and I don't necessarily know where the persistent storage is kept but should be below /var/lib/docker/volumes).
 +docker run -v [container folder]
 +docker run -v /var/lib/mysql/data
 +
 +# A named volume (Note: I am only showing the -v flag, again I may not know where the storage is kept but should be below /var/lib/docker/volumes, plus I am able to reference it better than an anonymous volume).
 +
 +</code>
  
 +===== Packaging & Distributing Your Own Docker Containers into Images =====
  
 +Again, check with Nina on how to do this. Clients of Dockerized applications would not normally have to do any of this.
  
 +{{youtube>3c-iBn73dDE?medium&start=6120&end=8844}}
Print/export