Skip to content
No description or website provided.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Docker Bootcamp


  1. Get Started
  2. Volumes
  3. Dockerfile
  4. Tips & Tricks

Get Started

Common commands:

command description
docker images List images
docker run Run a command in a new container
docker ps List containers (shortcut for docker container ls)
docker stop CONTAINER Stop one or more running containers by id or name
docker rm CONTAINER Remove one or more containers
docker rmi IMAGE Remove one or more images
docker save IMAGE Save one or more images to a tar archive (streamed to STDOUT by default)

docker run

Common docker run arguments are:

argument description
--rm Automatically remove the container when it exits
-p Publish a container's port(s) to the host (-p host_port:container_port)
-v Bind mount a volume (-v host_directory:container_directory)
-w Working directory inside the container
-ti Allocate a pseudo-TTY and keep STDIN open even if not attached
-e Set environment variables (-e ENV_NAME=env_value)
-d Run container in background and print container ID
--name Assign a name to the container


PHP + Apache

# interactive shell
docker run --rm -ti php:7.1-cli

docker run --rm -ti -p 8080:80 -v $(pwd)/example/apache-php/public:/usr/src/myapp -w /usr/src/myapp php:7.1-cli -S
docker run --rm -ti -p 8080:80 -v $(pwd)/example/apache-php/public:/usr/src/myapp -w /usr/src/myapp php:7.2-cli -S
docker run --rm -ti -p 8080:80 -v $(pwd)/example/apache-php/public:/usr/src/myapp -w /usr/src/myapp php:7.3-cli -S

docker run --rm -d -p 80:80 --name my-apache-php-app -v $(pwd)/example/apache-php/public:/var/www/html php:7.3-apache
docker stop my-apache-php-app

docker run --rm -ti -p 80:80 -v $(pwd)/example/apache-php/public:/var/www/html php:7.3-apache


# iteractive shell
docker run --rm -ti node

docker run --rm -ti -v $(pwd)/example/nodejs:/www -w /www node npm install
docker run --rm -ti -v $(pwd)/example/nodejs:/www -w /www -p 3000:3000 node npm start

Jenkins + BlueOcean

docker run -u root --rm -d -p 49990:8080 -p 50000:50000 --name jenkinsci -v jenkins-data:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkinsci/blueocean

# show containers
docker ps -a

# CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                               NAMES
# 2f76b46560bd        jenkinsci/blueocean   "/sbin/tini -- /usr/…"   10 minutes ago      Up 10 minutes>50000/tcp,>8080/tcp   jenkinsci

# execute bash command interactively in container ID '2f76b46560bd'
docker exec -it 2f76b46560bd bash

docker stop 2f76b46560bd


docker volume ls
docker inspect compose_db_data
# [
#     {
#         "CreatedAt": "2019-04-10T07:25:55Z",
#         "Driver": "local",
#         "Labels": {
#             "com.docker.compose.project": "compose",
#             "com.docker.compose.version": "1.23.2",
#             "com.docker.compose.volume": "db_data"
#         },
#         "Mountpoint": "/var/lib/docker/volumes/compose_db_data/_data",
#         "Name": "compose_db_data",
#         "Options": null,
#         "Scope": "local"
#     }
# ]

docker run --rm -it --privileged --pid=host justincormack/nsenter1

# / #  ls /var/lib/docker/volumes/compose_db_data/_data


Tips & Tricks


As a DigitalOcean fanboy, I'm working with containers on RancherOS that is a container distributions easy to install on DO.


Here a list of useful aliases:

# git
alias git="docker run --rm -ti -v $(pwd):/git -v $HOME/.ssh:/root/.ssh alpine/git"

# node
export DOCKER_TAG_NODE=latest
alias node="docker run --rm -ti -v $(pwd):/www -w /www node:$DOCKER_TAG_NODE node"
alias  npm="docker run --rm -ti -v $(pwd):/www -w /www node:$DOCKER_TAG_NODE npm"

node () {
  docker run --rm -ti -v $(pwd):/www -w /www node:$1 node ${@:2};

npm () {
  docker run --rm -ti -v $(pwd):/www -w /www node:$1 npm ${@:2};

# php
export DOCKER_TAG_PHP=latest
alias php="docker run --rm -ti -v $(pwd):/www -w /www php:$DOCKER_TAG_PHP php"
alias php-server="docker run --rm -ti -v $(pwd):/www -w /www -p 8080:8080 php:$DOCKER_TAG_PHP php -S"

php () {
  docker run --rm -ti -v $(pwd):/www -w /www php:$1 php ${@:2};
You can’t perform that action at this time.