Docker Compose Cheat Sheet

broken image


  1. Docker Commands List
  2. Docker Compose Cheat Sheet
  3. Dockerfile Cheat Sheet
  4. Docker Cheat Sheet Pdf
  5. Docker Commands Pdf

An overview of the most important commands for managing Sitecore with Docker.

The official Docker documentation is very good, but it can be difficult to navigate. This topic lists some of the most useful commands for managing Sitecore with Docker in local development environments.

The examples assume that you use PowerShell as your command shell.

These commands show various information about Docker itself:

List
  • To list all available commands:

    You can display detailed information for any specific command using --help:

  • To display high-level information for your Docker environment (version, root directory, default isolation mode, and so on):

LZone Cheats Sheets. Docker Compose Cheat Sheet Edit Cheat Sheet Setup Troubleshooting Couldn't connect to Docker daemon at http+docker://localhost - is it running? Cheat Sheet - Docker. Cheat Sheet; Docker; Network; Security; Shell; Snippets; Aug 18, 2019. Docker daemon Enable buildkit. Added RUN groupadd -r rabbitmq && useradd -r-d /var/lib/rabbitmq -m-g rabbitmq rabbitmq # vs. RUN groupadd user && useradd -create-home-home-dir /home/user -g user user # vs. # add our user and group first to make. Docker-compose up is used to start a project. It tries to automate a series of operations including building a mirror, (re)creating a service, starting a service, and associating a service-related container. Sometimes you will need docker-compose up -rebuild after making code changes. Docker Cheat Sheet Process Management # Show all running docker containers docker ps # Show all docker containers docker ps -a # Run a container docker run: # Run a container and connect to it. # Show docker-compose resource consumption docker-compose top.

You use these commands to manage images:

  • To list images (use -a to include intermediate images):

    You can format the results with the --format option. See the Docker documentation for a list of valid placeholders.

  • To remove images:

    The can be either the image ID or full name. The ID only requires the minimum number of characters to uniquely identify it. For example, given this image list:

    All 3 of these commands remove the nanoserver image:

  • To remove all images:

    To be more selective, use image list formatting combined with findstr. For example, to remove all images with a specific name or tag:

  • To inspect images:

    This displays detailed information for an image, including:

    • ID: The full unique identifier of the image.

    • WorkingDir: The folder you are in when you run an interactive shell in the image. You use this when you extend an image with your own customizations.

    • Entrypoint: The default entrypoint when you run this image in a container. This is useful information when you use the image in Docker Compose, which allows overriding.

    • VirtualSize: The size of the image in bytes.

    You can format the output.

You use these commands to manage containers:

  • To list containers (use -a to include stopped containers):

    You can filter the results using the -f (or --filter) option. For example, to show just the running Sitecore CM images:

    You can format the results with the --format option. See the Docker documentation for a list of valid placeholders.

  • To remove containers (use -v to remove volumes as well):

    Similar to images, the can be either the container ID (full or partial) or full name.

  • To remove all stopped containers:

    (Add --force to remove running containers as well.)

  • To inspect containers:

    This displays detailed information for a container, including the following:

    • ID - the full unique identifier of the container.

    • Image - the image the container is running.

    • NetworkSettings - the network information including the Ports, IPAddress, and any Aliases.

    • LogPath - the file system path to the container's log file.

    • Volumes - displays any volume mappings between the host system and the container.

    • WorkingDir - this is where you are dropped when running an interactive shell in the container.

    You can format the output.

  • To start and stop containers individually:

    However, when you develop with Sitecore, you usually have multiple containers and use Docker Compose to start and stop containers.

  • To copy files between containers and the local file system:

    For example, to copy a file to a container:

    Or to copy a folder from a container:

    Note

    Your containers must be running with process isolation for this. File system operations with Hyper-V container are not supported.

  • To display logs:

    You can stream the log output using -f (or --follow):

    Type Ctrl+C to exit.

    Most containers generate a lot of entries, so you can use the --tail or --until options to limit the amount. For example, to display only the last 20 log entries:

Many of the Docker commands provide the --format or -f option to format results, which allows you to format the output for display or even to pass to other scripts. The format string follows Go templating.

Spacex orbital launch table. For inspect commands, the output data is already in JSON format, so the data structure is straightforward.

Some examples:

  • To get a container's image name:

  • To get a container's IP address:

    The output from list commands is in a table format. The Docker documentation (see here for images, here for containers) has details about the available properties, or you can format the output as JSON as follows:

  • To show a custom image list:

  • To show a custom container list, using the table directive:

You can open an interactive shell prompt inside a Windows image. You can only use powershell in images that support it. If omitted, the default cmd shell is used:

Type exit to return out of the container to your previous shell session.

This starts a new container (run), goes into an interactive shell (-it), and then destroys the container after you exit (--rm).

This does not work for all images, depending on the default ENTRYPOINT. If this is the case, run it in detached mode:

Then run an interactive shell in the running container.

You can open an interactive shell prompt inside a running Windows container using the following.You can only use powershell in containers that support it:

Type exit to return out of the container to your previous shell session.

Docker does not remove unused resources automatically. Unnecessary resources can therefore accumulate over time and use up disk space.

The most useful command to solve this issue is:

Docker compose cheatsheet pdf

By default, you are prompted to continue. To bypass, use the -f (or --force) option.

This command removes:

  • All stopped containers.

  • All networks not used by at least one container.

  • All dangling images (not tagged and not referenced by any container).

  • All build caches.

This default is generally safe to use at any time. You can add the following options to be more aggressive about it:

  • --volumes - Removes all volumes not used by at least one container

  • -a (or --all) - Removes all images without at least one container associated with them

There are prune commands for each individual Docker object (image, container, and so on), but those are used less often. See the Docker documentation for details.

You run these commands from the location of your Compose file. They assume that your Compose file is called docker-compose.yml. They will also automatically load an additional docker-compose.override.yml, if such a file is present.

If your Compose files are named something else, use the -f flag to specify explicitly:

You can specify as many files as you need. Compose combines them into a single configuration based on the order, with subsequent files overriding/adding to their predecessors.

You can view the aggregated result using config. For example:

This shows your resolved application configuration, including combined compose files, .env, and so on. You can also add the name of one or more services. This allows you to target individual services or containers. For example, given the following Compose file:

You can restart just the id and cm containers:

  • To create and start containers:

    This creates and run containers for all services that you have defined in your Compose configuration.

    The -d (detached mode) starts the containers in the background and leaves them running. If you omit this, the container logs are streamed to the output, and you need to type Ctrl+C to return to a prompt. This also stops and removes your containers.

  • To stop containers:

    This stops containers but does not remove the containers.

  • To start containers:

    This starts existing containers that you have previously stopped.

  • To restart containers:

    This restarts all stopped and running containers.

  • To stop and remove containers:

    This stops all containers gracefully, and once all are stopped, it removes them. Any networks created by up are also removed. Use -v to remove volumes.

  • To list containers:

    You can list the names of the services instead with the --services option. Use -a to include stopped containers.

  • To build images:

    This builds and creates images for all services that define a build.

    You can use the --build option with up. This rebuilds and runs containers with the latest code:

  • To display logs:

    This displays the logs from all containers. You can use the --tail option to limit the number of lines, and filter for specific containers. For example, to display only the last 20 log entries from your cm and xconnect containers:

    You can also stream the log output with the -f (or --follow) option:

    Type Ctrl+C to exit.

docker daemon

Enable buildkit

Add to /etc/docker/daemon.json:

docker-compose

Devices

Labels

External Network

Dockerfile

Docker Stop Signal

imagemagick

vim

path update

download & extract tar.gz

gpg dirmgr explained

purge

list what exposed ports do

cassandra

gosu

debian

Docker

copy with proper permissions

su-exec

setgid

Docker Commands List

npm

gosu

tini

node

redis

docker

google cloud sdk

kubectl

pip

locale

tomcat

https://github.com/Unidata/tomcat-docker/blob/master/Dockerfile

gosu tomcat

Secure repository setup

Docker Compose Cheat Sheet

create application folder structure

Docker commands list
  • To list all available commands:

    You can display detailed information for any specific command using --help:

  • To display high-level information for your Docker environment (version, root directory, default isolation mode, and so on):

LZone Cheats Sheets. Docker Compose Cheat Sheet Edit Cheat Sheet Setup Troubleshooting Couldn't connect to Docker daemon at http+docker://localhost - is it running? Cheat Sheet - Docker. Cheat Sheet; Docker; Network; Security; Shell; Snippets; Aug 18, 2019. Docker daemon Enable buildkit. Added RUN groupadd -r rabbitmq && useradd -r-d /var/lib/rabbitmq -m-g rabbitmq rabbitmq # vs. RUN groupadd user && useradd -create-home-home-dir /home/user -g user user # vs. # add our user and group first to make. Docker-compose up is used to start a project. It tries to automate a series of operations including building a mirror, (re)creating a service, starting a service, and associating a service-related container. Sometimes you will need docker-compose up -rebuild after making code changes. Docker Cheat Sheet Process Management # Show all running docker containers docker ps # Show all docker containers docker ps -a # Run a container docker run: # Run a container and connect to it. # Show docker-compose resource consumption docker-compose top.

You use these commands to manage images:

  • To list images (use -a to include intermediate images):

    You can format the results with the --format option. See the Docker documentation for a list of valid placeholders.

  • To remove images:

    The can be either the image ID or full name. The ID only requires the minimum number of characters to uniquely identify it. For example, given this image list:

    All 3 of these commands remove the nanoserver image:

  • To remove all images:

    To be more selective, use image list formatting combined with findstr. For example, to remove all images with a specific name or tag:

  • To inspect images:

    This displays detailed information for an image, including:

    • ID: The full unique identifier of the image.

    • WorkingDir: The folder you are in when you run an interactive shell in the image. You use this when you extend an image with your own customizations.

    • Entrypoint: The default entrypoint when you run this image in a container. This is useful information when you use the image in Docker Compose, which allows overriding.

    • VirtualSize: The size of the image in bytes.

    You can format the output.

You use these commands to manage containers:

  • To list containers (use -a to include stopped containers):

    You can filter the results using the -f (or --filter) option. For example, to show just the running Sitecore CM images:

    You can format the results with the --format option. See the Docker documentation for a list of valid placeholders.

  • To remove containers (use -v to remove volumes as well):

    Similar to images, the can be either the container ID (full or partial) or full name.

  • To remove all stopped containers:

    (Add --force to remove running containers as well.)

  • To inspect containers:

    This displays detailed information for a container, including the following:

    • ID - the full unique identifier of the container.

    • Image - the image the container is running.

    • NetworkSettings - the network information including the Ports, IPAddress, and any Aliases.

    • LogPath - the file system path to the container's log file.

    • Volumes - displays any volume mappings between the host system and the container.

    • WorkingDir - this is where you are dropped when running an interactive shell in the container.

    You can format the output.

  • To start and stop containers individually:

    However, when you develop with Sitecore, you usually have multiple containers and use Docker Compose to start and stop containers.

  • To copy files between containers and the local file system:

    For example, to copy a file to a container:

    Or to copy a folder from a container:

    Note

    Your containers must be running with process isolation for this. File system operations with Hyper-V container are not supported.

  • To display logs:

    You can stream the log output using -f (or --follow):

    Type Ctrl+C to exit.

    Most containers generate a lot of entries, so you can use the --tail or --until options to limit the amount. For example, to display only the last 20 log entries:

Many of the Docker commands provide the --format or -f option to format results, which allows you to format the output for display or even to pass to other scripts. The format string follows Go templating.

Spacex orbital launch table. For inspect commands, the output data is already in JSON format, so the data structure is straightforward.

Some examples:

  • To get a container's image name:

  • To get a container's IP address:

    The output from list commands is in a table format. The Docker documentation (see here for images, here for containers) has details about the available properties, or you can format the output as JSON as follows:

  • To show a custom image list:

  • To show a custom container list, using the table directive:

You can open an interactive shell prompt inside a Windows image. You can only use powershell in images that support it. If omitted, the default cmd shell is used:

Type exit to return out of the container to your previous shell session.

This starts a new container (run), goes into an interactive shell (-it), and then destroys the container after you exit (--rm).

This does not work for all images, depending on the default ENTRYPOINT. If this is the case, run it in detached mode:

Then run an interactive shell in the running container.

You can open an interactive shell prompt inside a running Windows container using the following.You can only use powershell in containers that support it:

Type exit to return out of the container to your previous shell session.

Docker does not remove unused resources automatically. Unnecessary resources can therefore accumulate over time and use up disk space.

The most useful command to solve this issue is:

By default, you are prompted to continue. To bypass, use the -f (or --force) option.

This command removes:

  • All stopped containers.

  • All networks not used by at least one container.

  • All dangling images (not tagged and not referenced by any container).

  • All build caches.

This default is generally safe to use at any time. You can add the following options to be more aggressive about it:

  • --volumes - Removes all volumes not used by at least one container

  • -a (or --all) - Removes all images without at least one container associated with them

There are prune commands for each individual Docker object (image, container, and so on), but those are used less often. See the Docker documentation for details.

You run these commands from the location of your Compose file. They assume that your Compose file is called docker-compose.yml. They will also automatically load an additional docker-compose.override.yml, if such a file is present.

If your Compose files are named something else, use the -f flag to specify explicitly:

You can specify as many files as you need. Compose combines them into a single configuration based on the order, with subsequent files overriding/adding to their predecessors.

You can view the aggregated result using config. For example:

This shows your resolved application configuration, including combined compose files, .env, and so on. You can also add the name of one or more services. This allows you to target individual services or containers. For example, given the following Compose file:

You can restart just the id and cm containers:

  • To create and start containers:

    This creates and run containers for all services that you have defined in your Compose configuration.

    The -d (detached mode) starts the containers in the background and leaves them running. If you omit this, the container logs are streamed to the output, and you need to type Ctrl+C to return to a prompt. This also stops and removes your containers.

  • To stop containers:

    This stops containers but does not remove the containers.

  • To start containers:

    This starts existing containers that you have previously stopped.

  • To restart containers:

    This restarts all stopped and running containers.

  • To stop and remove containers:

    This stops all containers gracefully, and once all are stopped, it removes them. Any networks created by up are also removed. Use -v to remove volumes.

  • To list containers:

    You can list the names of the services instead with the --services option. Use -a to include stopped containers.

  • To build images:

    This builds and creates images for all services that define a build.

    You can use the --build option with up. This rebuilds and runs containers with the latest code:

  • To display logs:

    This displays the logs from all containers. You can use the --tail option to limit the number of lines, and filter for specific containers. For example, to display only the last 20 log entries from your cm and xconnect containers:

    You can also stream the log output with the -f (or --follow) option:

    Type Ctrl+C to exit.

docker daemon

Enable buildkit

Add to /etc/docker/daemon.json:

docker-compose

Devices

Labels

External Network

Dockerfile

Docker Stop Signal

imagemagick

vim

path update

download & extract tar.gz

gpg dirmgr explained

purge

list what exposed ports do

cassandra

gosu

debian

copy with proper permissions

su-exec

setgid

Docker Commands List

npm

gosu

tini

node

redis

docker

google cloud sdk

kubectl

pip

locale

tomcat

https://github.com/Unidata/tomcat-docker/blob/master/Dockerfile

gosu tomcat

Secure repository setup

Docker Compose Cheat Sheet

create application folder structure

Download and clean up in one layer

Package Manager tricks

Dockerfile Cheat Sheet

Metadata

Make sure to add ARG statements as late as possible to not invalidate the layer cache needlessly.Each ARG will be prepended to all subsequent RUN statements, i.e. building an image with the following Dockerfile docker --pull --tag foo:latest --build-arg GIT_COMMIT=46e24af6 --build-arg USERNAME=flask .

Docker Cheat Sheet Pdf

Effectively results in the following calls:

Docker Commands Pdf

Since the git commit hash will typically change with each build the build will not make good use of Docker's layer cache

Python

Golang





broken image