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 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>
-
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 somedocker build
command -
docker rmi -f $(docker images -q --filter "dangling=true")
- remove all images - images without tags, something like cleanup