Docker

From Resonite Wiki
Revision as of 22:41, 13 March 2024 by ProbablePrime (talk | contribs) (Created page with "Here's some basic Docker information. That might help. == Basic commands == * <code>docker pull <image></code> - Downloads the image locally * <code>docker run <parameters> <image></code> - 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: ** <code>-p <sourcePort>:<desinationPort></code> - Opens a port from within the container to your machine (specify <code>127.0.0.1:</code...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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 sample one looks like this:

<syntaxhighlight lang="yaml"> version: '3.8'

services:

 hello-world:
   image: hello-world

</syntax>

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