Docker

Pulling docker images and running them as containers

Pulling images

docker pull alpine:latest

List images:

docker image ls

Or:

docker images

To remove an image:

docker image remove alpine:latest

To remove all images (without an associated container):

docker image prune --all

Running images as containers

If the image is not already pulled, it will automatically be pulled, and so there is generally no need to manually pull images.

docker container create --name container_name alpine:latest
docker create --name container_name alpine:latest

If no name is provided, a random one will be created.

Once a container has been created, it can be started.

List containers. The "a" flag makes it show all containers, not just those running.

docker ps -a
docker container start container_name
docker start container_name

We can run it interactively and with a TTY.

docker container start --interactive --tty container_name
docker start -it container_name

Run can be used instead of create and start.

docker container run -it --name container_name alpine:latest
docker run -it --name container_name alphine:latest

Stopping containers.

sudo docker kill $(sudo docker ps -q)

Removing containers.

sudo docker rm $(sudo docker ps -a -q)
sudo docker system prune -af (this does much more than other stuff, saved lots of space. what does it do?)

Working without root

Building images from dockerfiles

Docker files and building images

First, build the images.

docker build -t "ae:tensorflow" -f ./docker/tf/Dockerfile_jetson.gpu .

Build

docker build -t localhost:32000/homepage-nodejs -f ./docker/web/Dockerfile .

Detaching containers

Detaching

docker run --detach
docker run -d

Running on reboot

making things start on reboot

docker run -d --restart=always

SSH into detached containers

docker exec -it <container_name> /bin/bash

Registry

Pushing images to repos

docker run -d -p 5000:5000 --restart=always --name registry registry:2
docker tag ubuntu:16.04 localhost:5000/my-ubuntu
docker push localhost:5000/my-ubuntu
docker pull localhost:5000/my-ubuntu
docker image remove localhost:5000/my-ubuntu

sudo docker push localhost:32000/homepage-nodejs

docker container stop registry
docker container stop registry && docker container rm -v registry

Volumes

Introduction

Network

Introduction

Docker compose

Docker Compose

sudo docker-compose build --no-cache
sudo docker-compose up --detach

can delete old databases if interacting badly

sudo rm -rf /data/db/artificialeconomist_mongo