Docker

From Resonite Wiki
Revision as of 00:56, 14 March 2024 by AdamSkI2003 (talk | contribs) (add documentation link to bigger compose file sample)

Here's some basic Docker information. That might help.

Basic commands

  • docker pull <image> - Downloads the image locally
  • docker 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 (specify 127.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 variable SOMETHING to the value value.
    • -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 containers
  • docker 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 very basic sample one looks like this:

version: '3.8'

services:
  hello-world:
    image: hello-world

Refer to the documentation for a more complete example.

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
  • 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 instance docker compose logs -f (you will need to do CTRL+C to break out of this)
  • docker compose stop <service> - Will stop the container created for the service, for instance docker compose stop hello-world
  • docker compose down - Will stop all the services specified in the configuration and destroy their containers
  • docker 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

See Also