Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
articles:linux:docker-reference-page [2022/02/12 15:24] tom [Base Questions] |
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 | ||
| </ | </ | ||
| Line 75: | Line 78: | ||
| ===== Docker Compose ===== | ===== Docker Compose ===== | ||
| - | Placeholders are in square [] brackets and comments are in curly {} braces in the template below. Note that in the template I have laid out 2 different Docker containers in a single compose file. When you do this, a common Docker network is created. | + | Placeholders are in square [] brackets and comments are in curly {} braces in the template below. Note that in the template I have laid out 2 different Docker containers in a single compose file. When you do this, a common Docker network is created. Also, indentation must be precise for this to work (supposedly). |
| < | < | ||
| version:' | version:' | ||
| services: | services: | ||
| - | [user assigned name]: {same as docker run --name flag} | + | |
| - | | + | image: [image name][: |
| - | | + | ports: |
| - | | + | - [host port]: |
| - | | + | |
| - | | + | - [user reference name]: |
| - | | + | - [host path]: |
| - | | + | - [container path] {for an anonymous volume} |
| - | | + | |
| - | | + | - [environment setting]=[assigned value] |
| - | | + | [user assigned name]: {same as docker run --name flag} |
| - | | + | image: [image name][: |
| - | </ | + | ports: |
| + | - [host port]: | ||
| + | | ||
| + | - [user reference name]: | ||
| + | - [host path]: | ||
| + | - [container path] {for an anonymous volume} | ||
| + | | ||
| + | - [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} | ||
| + | |||
| + | </ | ||
| + | |||
| + | The contents of the file above would be saved in a text file saved with a .yaml extension. | ||
| + | |||
| + | To start a Docker compose file, run: | ||
| + | |||
| + | < | ||
| + | docker-compose [flags] [command] | ||
| + | -f [name of yaml file] | ||
| + | |||
| + | Commands: | ||
| + | |||
| + | up = start a Docker Compose configuration | ||
| + | down = stop a Docker Compose configuration | ||
| + | |||
| + | Examples: | ||
| + | |||
| + | docker-compose -f mycontainers.yaml up | ||
| + | docker-compose -f mycontainers.yaml down | ||
| + | </ | ||
| + | |||
| + | ===== Persistent Data with Docker Volumes ===== | ||
| + | |||
| + | 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. | ||
| + | |||
| + | < | ||
| + | # A defined volume (Note: I am only showing the -v flag). | ||
| + | docker run -v [host folder]: | ||
| + | docker run -v / | ||
| + | |||
| + | # 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 / | ||
| + | docker run -v [container folder] | ||
| + | docker run -v / | ||
| + | |||
| + | # 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 / | ||
| + | |||
| + | </ | ||
| + | ===== 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> | ||