Skip to content

Instantly share code, notes, and snippets.

@MirKml
Last active October 20, 2019 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MirKml/59920d2094f722769fd25b9cfbebed51 to your computer and use it in GitHub Desktop.
Save MirKml/59920d2094f722769fd25b9cfbebed51 to your computer and use it in GitHub Desktop.
docker-working.md

Build image

If we ha Dockerfile in current directory

$ docker build -t <imageTagName> [--target=<targetName>] .

Builds docker image with particular tag according Dockerfile from current directory. COPY during build - is relative to direcotory with Dockerfile, is relative to WORKDIR

Run image

Run command on image according ENTRYPOINT

$ docker run <imageTagName>

Run other command (ls) on image without ENTRYPOINT

$ docker run <imageTagName> ls

Run other command (ls) on image with ENTRYPOINT - it overrides original entrypoint

$ docker run --entrypoint ls <imageTagName> <lsParameters>

Run bash on image from container

$ docker run -it <imageTagName> /bin/bash

Run the container with webserver in 'foreground' mode, There is port mapping between internal web server in container - tcp 80 and outer 3000. Logs from web server are printed into stdout/stderr. It's recommended to use container name - --name. It can be used on other docker container commands instead of container ID.

$ docker run -p 3000:80 -t <imageTagName> --name <containerName>

CTRL-C don't stop the container, it must be stopped with docker stop <containerName>, or kill with docker kill <containerName>

$ docker run -p 3000:80 -t <imageTagName> --name <containerName>

Run container with webserver in detached mode - as daemon.

$ docker run -d -p 3000:80 -t <imageTagName> --name <containerName>

Common operations on containers, images

  • docker ps - list of running, paused containers

  • docker kill <containeName|containerId> - list of running containers

  • docker rm $(docker ps -q --filter "status=exited") - remove stopped containers

  • docker images - list of pulled, created images

  • docker images bitnami/apache - list all pulled, created images by bitnami/apache repository

  • docker rmi bitnami/apache:latest - remove all images bitnami/apache:latest with all its children - usefull when you force to pull new version of upstream image for some docker build command

  • docker rmi -f $(docker images -q --filter "dangling=true") - remove all images - images without tags, something like cleanup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment