0% found this document useful (0 votes)
35 views17 pages

The Ultimate Docker Cheat Sheet - Dockerlabs

Uploaded by

bilgiyazan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views17 pages

The Ultimate Docker Cheat Sheet - Dockerlabs

Uploaded by

bilgiyazan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

31.03.

2023 18:16 The Ultimate Docker Cheat Sheet | dockerlabs

Star 3,413 Fork 1,633 Watch 179 Follow @collabnix 1,047

The Ultimate Docker Cheat Sheet


Docker - Beginners | Intermediate | Advanced

View on GitHub Join Slack Docker Cheatsheet Docker Compose Cheatsheet Follow us on Twitter

The Ultimate Docker Cheat Sheet

A cheatsheet is a concise summary of important information that is meant to be used as a quick reference.
Cheatsheets are often used in the form of a list or a table, and they typically cover a specific topic or subject
area. In the context of Docker, a Docker cheatsheet is a summary of commonly used Docker commands and
their options, as well as other useful information related to Docker.

Cheatsheets can be particularly helpful when learning a new tool or technology, as they provide a convenient
way to quickly look up and remind oneself of key concepts and commands. They can also be useful for
experienced users who need to recall a specific command or option but may not remember all the details.

https://dockerlabs.collabnix.com/docker/cheatsheet/#container-management-clis 1/17
31.03.2023 18:16 The Ultimate Docker Cheat Sheet | dockerlabs

Table of Contents
Categories
🐳 Basic Docker CLIs
🧰 Container Management CLIs
🧑‍💻 Inspecting the Container
🧑‍💻 Interacting with Container
🫙 Image Management Commands
🧪 Image Transfer Commands
🏗️Builder Main Commands
⚙️The Docker CLI
🧑‍🤝‍🧑 Contributors
💬 Support and Community
👉 References

Basic Docker CLIs


Here’s the list of the basic Docker commands that works on both Docker Desktop as well as Docker Engine:

Container Management CLIs


Here’s the list of the Docker commands that manages Docker images and containers flawlessly:

https://dockerlabs.collabnix.com/docker/cheatsheet/#container-management-clis 2/17
31.03.2023 18:16 The Ultimate Docker Cheat Sheet | dockerlabs

Inspecting The Container


Here’s the list of the basic Docker commands that helps you inspect the containers seamlessly:

https://dockerlabs.collabnix.com/docker/cheatsheet/#container-management-clis 3/17
31.03.2023 18:16 The Ultimate Docker Cheat Sheet | dockerlabs

Interacting with Container


Do you want to know how to access the containers? Check out these fundamental commands:

https://dockerlabs.collabnix.com/docker/cheatsheet/#container-management-clis 4/17
31.03.2023 18:16 The Ultimate Docker Cheat Sheet | dockerlabs

Image Management Commands


Here’s the list of Docker commands that helps you manage the Docker Images:

https://dockerlabs.collabnix.com/docker/cheatsheet/#container-management-clis 5/17
31.03.2023 18:16 The Ultimate Docker Cheat Sheet | dockerlabs

Image Transfer Commands


Here’s the list of Docker image transfer commands:

https://dockerlabs.collabnix.com/docker/cheatsheet/#container-management-clis 6/17
31.03.2023 18:16 The Ultimate Docker Cheat Sheet | dockerlabs

Builder Main Commands


Want to know how to build Docker Image? Do check out the list of Image Build Commands:

https://dockerlabs.collabnix.com/docker/cheatsheet/#container-management-clis 7/17
31.03.2023 18:16 The Ultimate Docker Cheat Sheet | dockerlabs

The Docker CLI

Manage images

docker build

docker build [options] .


-t "app/container_name" # name

Create an image from a Dockerfile.

docker run

docker run [options] IMAGE


# see `docker create` for options

https://dockerlabs.collabnix.com/docker/cheatsheet/#container-management-clis 8/17
31.03.2023 18:16 The Ultimate Docker Cheat Sheet | dockerlabs

Run a command in an image .

Manage containers

docker create

docker create [options] IMAGE


-a, --attach # attach stdout/err
-i, --interactive # attach stdin (interactive)
-t, --tty # pseudo-tty
--name NAME # name your image
-p, --publish 5000:5000 # port map
--expose 5432 # expose a port to linked containers
-P, --publish-all # publish all ports
--link container:alias # linking
-v, --volume `pwd`:/app # mount (absolute paths needed)
-e, --env NAME=hello # env vars

Example

$ docker create --name app_redis_1 \


--expose 6379 \
redis:3.0.2

Create a container from an image .

docker exec

docker exec [options] CONTAINER COMMAND


-d, --detach # run in background
-i, --interactive # stdin
-t, --tty # interactive

Example

$ docker exec app_web_1 tail logs/development.log


$ docker exec -t -i app_web_1 rails c

Run commands in a container .

https://dockerlabs.collabnix.com/docker/cheatsheet/#container-management-clis 9/17
31.03.2023 18:16 The Ultimate Docker Cheat Sheet | dockerlabs

docker start

docker start [options] CONTAINER


-a, --attach # attach stdout/err
-i, --interactive # attach stdin

docker stop [options] CONTAINER

Start/stop a container .

docker ps

$ docker ps
$ docker ps -a
$ docker kill $ID

Manage container s using ps/kill.

Images

docker images

$ docker images
REPOSITORY TAG ID
ubuntu 12.10 b750fe78269d
me/myapp latest 7b2431a8d968

$ docker images -a # also show intermediate

Manages image s.

docker rmi

docker rmi b750fe78269d

Deletes image s.

Also see
Getting Started (docker.io)

Dockerfile
Inheritance
https://dockerlabs.collabnix.com/docker/cheatsheet/#container-management-clis 10/17
31.03.2023 18:16 The Ultimate Docker Cheat Sheet | dockerlabs

FROM ruby:2.2.2

Variables

ENV APP_HOME /myapp


RUN mkdir $APP_HOME

Initialization

RUN bundle install

WORKDIR /myapp

VOLUME ["/data"]
# Specification for mount point

ADD file.xyz /file.xyz


COPY --chown=user:group host_file.xyz /path/container_file.xyz

Onbuild

ONBUILD RUN bundle install


# when used with another file

Commands

EXPOSE 5900
CMD ["bundle", "exec", "rails", "server"]

Entrypoint

ENTRYPOINT ["executable", "param1", "param2"]


ENTRYPOINT command param1 param2

Configures a container that will run as an executable.

ENTRYPOINT exec top -b

This will use shell processing to substitute shell variables, and will ignore any CMD or docker run command line
arguments.

https://dockerlabs.collabnix.com/docker/cheatsheet/#container-management-clis 11/17
31.03.2023 18:16 The Ultimate Docker Cheat Sheet | dockerlabs

Metadata

LABEL version="1.0"

LABEL "com.example.vendor"="ACME Incorporated"


LABEL com.example.label-with-value="foo"

LABEL description="This text illustrates \


that label-values can span multiple lines."

See also
https://docs.docker.com/engine/reference/builder/

docker-compose
Basic example

# docker-compose.yml
version: '2'

services:
web:
build: .
# build from Dockerfile
context: ./Path
dockerfile: Dockerfile
ports:
- "5000:5000"
volumes:
- .:/code
redis:
image: redis

Commands

docker-compose start
docker-compose stop

docker-compose pause
docker-compose unpause

docker-compose ps
docker-compose up
docker-compose down

https://dockerlabs.collabnix.com/docker/cheatsheet/#container-management-clis 12/17
31.03.2023 18:16 The Ultimate Docker Cheat Sheet | dockerlabs

Reference

Building

web:
# build from Dockerfile
build: .

# build from custom Dockerfile


build:
context: ./dir
dockerfile: Dockerfile.dev

# build from image


image: ubuntu
image: ubuntu:14.04
image: tutum/influxdb
image: example-registry:4000/postgresql
image: a4bc65fd

Ports

ports:
- "3000"
- "8000:80" # guest:host

# expose ports to linked services (not to host)


expose: ["3000"]

Commands

# command to execute
command: bundle exec thin -p 3000
command: [bundle, exec, thin, -p, 3000]

# override the entrypoint


entrypoint: /app/start.sh
entrypoint: [php, -d, vendor/bin/phpunit]

Environment variables

# environment vars
environment:
RACK_ENV: development

https://dockerlabs.collabnix.com/docker/cheatsheet/#container-management-clis 13/17
31.03.2023 18:16 The Ultimate Docker Cheat Sheet | dockerlabs

environment:
- RACK_ENV=development

# environment vars from file


env_file: .env
env_file: [.env, .development.env]

Dependencies

# makes the `db` service available as the hostname `database`


# (implies depends_on)
links:
- db:database
- redis

# make sure `db` is alive before starting


depends_on:
- db

Other options

# make this service extend another


extends:
file: common.yml # optional
service: webapp

volumes:
- /var/lib/mysql
- ./_data:/var/lib/mysql

Advanced features

Labels

services:
web:
labels:
com.example.description: "Accounting web app"

DNS servers

services:
web:
dns: 8.8.8.8
dns:

https://dockerlabs.collabnix.com/docker/cheatsheet/#container-management-clis 14/17
31.03.2023 18:16 The Ultimate Docker Cheat Sheet | dockerlabs

- 8.8.8.8
- 8.8.4.4

Devices

services:
web:
devices:
- "/dev/ttyUSB0:/dev/ttyUSB0"

External links

services:
web:
external_links:
- redis_1
- project_db_1:mysql

Hosts

services:
web:
extra_hosts:
- "somehost:192.168.1.100"

sevices
To view list of all the services runnning in swarm

docker service ls

To see all running services

docker stack services stack_name

to see all services logs

docker service logs stack_name service_name

To scale services quickly across qualified node

docker service scale stack_name_service_name=replicas

clean up
https://dockerlabs.collabnix.com/docker/cheatsheet/#container-management-clis 15/17
31.03.2023 18:16 The Ultimate Docker Cheat Sheet | dockerlabs

To clean or prune unused (dangling) images

docker image prune

To remove all images which are not in use containers , add - a

docker image prune -a

To prune your entire system

docker system prune

To leave swarm

docker swarm leave

To remove swarm ( deletes all volume data and database info)

docker stack rm stack_name

To kill all running containers

docker kill $(docekr ps -q )

Contributors
Sangam biradar - Docker Community Leader
Ajeet Singh Raina - Docker Captain, Collabnix

Support and Community


If you do get enough interest to contributer to this Cheat Sheet, the community at Collabnix is available to
support you. Feel free to raise PR and get your favorite Cheat Sheet added to the list via PR, or you can connect
to us either on Slack or Discord server.

Other Cheat Sheets


Kubectl Cheat Sheet
Docker Compose Cheat Sheet

Practice Docker Tutorial


free Ubuntu VM

https://dockerlabs.collabnix.com/docker/cheatsheet/#container-management-clis 16/17
31.03.2023 18:16 The Ultimate Docker Cheat Sheet | dockerlabs

Join Collabnix Discord Channel

129 Members Online

General

MEMBERS ONLINE
! Mario
24/7 🔊
2saif4u
alentino Hsiao Mount & Blade II: Bannerlord
ancieque
AndréCosolin
AnnaH
AprilWar
Autumn Heart
Ballin't
bjp
breadNbutter
Carpincho
Ch AI
Hangout with people who get it Join Discord

Tweets from @collabnix Follow on Twitter

Collabnix @collabnix · Mar 29


Spin up IRIS for Health #Docker container in compute...@InterSystems

dev.to
Guide how to run and use IRIS for Health docker image in GCloud
dockerlabs is maintained by collabnix.
This page was generated by GitHub Pages.
0.67g of CO2/view Website Carbon
Cleaner than 37% of pages tested

https://dockerlabs.collabnix.com/docker/cheatsheet/#container-management-clis 17/17

You might also like