Skip to content

reyadussalahin/docker-cheatsheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

Docker Cheatsheet

Be ready always

License Stars Forks PRs Issues


Docker Cheatsheet is here to help you with solving from basic to advanced common docker problems. It's a recipe for making docker usage as enjoyable as possible in your daily life.


Connect with me in linkedin or say hi to Twitter.

Contents

Conventions

  1. iname means image name with tag
  2. cname means container name
  3. vname means volume name
  4. nname means network name
  5. cid means container id
  6. cport means port in container
  7. hport means port in host
  8. cdir means directory in container
  9. hdir means directory in host
  10. /p/t/ means /path/to/

Commands

Image Related

$ docker image pull <iname>                          # pulls image from registry
$ docker image ls                                    # lists images
$ docker image build -t <iname> .                    # builds image from Dockerfile in current dir
$ docker image build -t <iname> -f </p/t/dockerfile> # builds image from dockerfile with given path
$ docker image rm <iname>                            # removes image

Container Related

Running Container

$ docker container run <iname>                  # runs container with an arbitrary name
$ docker container run --name <cname> <iname>   # runs container with a preferred name 
$ docker container run -it <iname> <cmd>        # runs container in interactive mode with given cmd
$ docker container run -d <iname>               # runs container in detached mode
$ docker container run -dit <iname>             # runs container in detached interactive mode

Lisiting Containers

$ docker container ls                           # lists running containers
$ docker container ps -a                        # lists all(both running and stopped) containers

Start, Stop, Attach and Removing Container

$ docker container stop <cid>                   # stops a container with given container id
$ docker container stop <cname>                 # stops a container with given container name
$ docker container start <cid>                  # restarts a stopped container
$ docker container start <cname>                # restarts a stopped container
$ docker container attach <cid>                 # attaches a running docker container
$ docker container attach <cname>               # attaches a running docker container
$ docker container rm <cid>                     # removes a container
$ docker container rm <cname>                   # removes a container

Executing command inside Container

$ docker container exec <cid> <cmd>         # executes cmd inside container with given id
$ docker container exec <cname> <cmd>       # executes cmd inside container with given name
$ docker container exec -it <cid> <cmd>     # executes cmd inside container in interactive mode
$ docker container exec -it <cname> <cmd>   # executes cmd inside container in interactive mode

Publishing Ports

$ docker container run -p <hport>:<cport> <iname>        # publishes container port in host port

Binding directories

$ docker container run -v /p/t/hdir:/p/t/cdir <iname>    # binds host dir to container dir

License

This repository is published under MIT License. To know more about license please visit this link.

Contributing

I'll continue to improve this repository. So, watch this repo. If you want to contribute, please read this guide.

Releases

No releases published

Packages

No packages published