No edit summary |
AdamSkI2003 (talk | contribs) better example compose file |
||
(3 intermediate revisions by the same user not shown) | |||
Line 14: | Line 14: | ||
== Compose == | == Compose == | ||
Compose is a tool provided by Docker that makes it trivial to deploy software following a defined configuration file written in YAML. A compose file is usually named <code>docker-compose.yml</code> and a sample one looks like this: | Compose is a tool provided by Docker that makes it trivial to deploy software following a defined configuration file written in YAML. A compose file is usually named <code>docker-compose.yml</code> and a sample one looks like this (the text after # characters is comments and it's ignored by Compose): | ||
<syntaxhighlight lang="yaml"> | <syntaxhighlight lang="yaml"> | ||
services: | version: '3.8' # not actually needed, but defined in the spec for backward compatibility | ||
services: # you can define one or multiple services here | |||
</ | whoami: # name of the service | ||
image: traefik/whoami # the Docker image to run, the example image is a small webserver that returns some system info | |||
restart: always # restart policy, can be always, on-failure, unless-stopped or "no"; you usually want always or unless-stopped | |||
volumes: # works like the -v flag for Docker; volumes aren't needed for the whoami image, they're in the example for illustrative purposes | |||
- /path/local:/path/inside # mounts /path/local on the host to /path/inside in the container; creates the directory on the host if it doesn't exist | |||
- /also/local:/also/inside:ro # mounts /also/local on the host to /also/inside in the container with read only permissions | |||
ports: # works like the -p flag for Docker | |||
- 8080:80 # exposes port 80 in the container to port 8080 on the host | |||
</syntaxhighlight> | |||
Refer to the [https://docs.docker.com/compose/compose-application-model/#illustrative-example documentation] for more examples. | |||
== Compose Commands == | == Compose Commands == | ||
Line 37: | Line 47: | ||
== See Also == | == See Also == | ||
* [[Headless Client/Docker| Using Docker to run a headless]] | * [[Headless Client/Docker| Using Docker to run a headless]] | ||
* [https://docs.docker.com/ Docker documentation] | |||
* [https://docs.docker.com/compose/ Docker Compose documentation] |
Latest revision as of 17:42, 26 March 2024
Here's some basic Docker information. That might help.
Basic commands
docker pull <image>
- Downloads the image locallydocker run <parameters> <image>
- Creates and starts a container with the specified image (doing CTRL+C or closing the prompt will stop it by default), some common parameters are:-p <sourcePort>:<desinationPort>
- Opens a port from within the container to your machine (specify127.0.0.1:
before the port specification to only open it locally)-d
- Detaches from the image, AKA runs it in the background-e SOMETHING=value
- Sets an environment variable, in this case sets the env variableSOMETHING
to the valuevalue
.-v /path/local:/path/inside
- Binds a local path into the container, usually used to pass files or persist data such as databases
docker container list --all
- Lists all created containersdocker container <stop/start/rm> <container name/ID>
- Will stop, start or remove the specified container
Compose
Compose is a tool provided by Docker that makes it trivial to deploy software following a defined configuration file written in YAML. A compose file is usually named docker-compose.yml
and a sample one looks like this (the text after # characters is comments and it's ignored by Compose):
version: '3.8' # not actually needed, but defined in the spec for backward compatibility
services: # you can define one or multiple services here
whoami: # name of the service
image: traefik/whoami # the Docker image to run, the example image is a small webserver that returns some system info
restart: always # restart policy, can be always, on-failure, unless-stopped or "no"; you usually want always or unless-stopped
volumes: # works like the -v flag for Docker; volumes aren't needed for the whoami image, they're in the example for illustrative purposes
- /path/local:/path/inside # mounts /path/local on the host to /path/inside in the container; creates the directory on the host if it doesn't exist
- /also/local:/also/inside:ro # mounts /also/local on the host to /also/inside in the container with read only permissions
ports: # works like the -p flag for Docker
- 8080:80 # exposes port 80 in the container to port 8080 on the host
Refer to the documentation for more examples.
Compose Commands
docker compose up <service(s) (optional)>
- Will start all the services or the ones specified, from the configuration file (doing CTRL+C or closing the prompt will close the service)- To run all the services in the background, you will need to append the
-d
argument, for instance:docker compose up -d
- To run all the services in the background, you will need to append the
docker compose logs <service(s) (optional)>
- Will display the logs of all the services or specified ones- You can also see the logs in real time by adding the argument
-f
, for instancedocker compose logs -f
(you will need to do CTRL+C to break out of this)
- You can also see the logs in real time by adding the argument
docker compose stop <service>
- Will stop the container created for the service, for instancedocker compose stop hello-world
docker compose down
- Will stop all the services specified in the configuration and destroy their containersdocker compose pull
- Will check if any service has a newer image available and if so, will download it- After running this, you will still need to do
docker compose up
so containers are re-created with the latest version downloaded
- After running this, you will still need to do