Docker

Docker hub

https://hub.docker.com/

Searching an Image

docker search <img-name>

Pull a Image

docker pull <image>:<version>

Run a Container

docker run -it <img-name> /bin/bash

Run a Container with ports + volume

-v = volume, -p = port, -d = detach

docker run --name <name> -d -p 80:80 -v /data/websites:/var/www <image/tag>

Run a command inside container

docker exec -it <container-name> bash

List Images

docker images

List all Containers

docker ps -a

List Volumes

docker volume ls

Commit a Image

docker commit <container-id> <name>

Save image to a tar.gz file

docker save --output name.tar <container-name>

Import image from a tar.gz file

docker load < name.tar

Start containers automatically

systemctl enable docker
docker run -dit --restart unless-stopped <container-name>

Renaming a Container

docker rename <old-name> <new-name>

 Delete a Container

docker rm <container-id>

Delete a Image

docker rmi <image-id>

Stop+Delete all Containers+Images

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -f status=exited -q)
docker rm $(docker ps -a -q)
docker rmi $(docker images -q)

Create a Dockerfile

Easy example:

FROM ubuntu:18.04
COPY . /app
RUN make /app
CMD python /app/app.py
  docker build -t <image/tag> .

More info here:  https://docs.docker.com/develop/develop-images/dockerfile_best-practices/

Docker Ignore

vim .dockerignore

badscript.sh
*.conf
README.md
docker build -t <image/tag> .