Skip to content

docker Notes

ipatch edited this page Feb 6, 2018 · 5 revisions

Table of Contents

General

  • Docker images do not contain a kernel, kernel modules (device drivers)

  • To find the name of a docker container

docker ps -a

macOS

💳 When using docker on on macOS, the images / containers are stored in

/Users/$USER/Library/Containers/
/Users/$USER/Library/Containers/com.docker.docker/Data/

Basics

Create a docker container based on CentOS 7 and drop-in to a bash prompt.

docker container run --rm -it centos:7 bash

--rm remove the docker container when it exits.
-i interactive
-t open a pseudo tty

To create a bridged docker network

docker network create <networkName>

Images

Docker images can be found at the below link
🐳

To show the history of a docker image

docker history <imageName>

To build a custom docker image locally within the current directory

docker image build -t <tag_name> .

-t specify a tag name for the current image being built.

Tagging

To learn about tagging in docker

docker image tag --help

Docker Hub

To push the latest changes of an image to the docker hub

docker image push <docker_username/image_name>

Make sure you are logged into the docker hub before pushing changes.

docker login

Note: after logging in with docker login the below file is written to store docker hub credentials.

/$HOME/$USER/.docker/config.json

Dockerfiles

To preserve sanity 👩‍⚕️ put the things that change the least at the top of the Dockerfile, and things that change the most at the bottom of the Dockerfile.

Docker Volumes

To cleanup unused volumes left behind from Docker containers

docker volume prune

Docker Compose

Docker compose comes bundled with the official Docker.app bundle from docker.com 💳

A simple docker workflow 💳

First get the <container_id> of the docker container to save.

docker ps -l

Then commit the changes you have made to the container.

docker commit <container_id> <docker_user_name>/<changes_made>

Then to load your container with the committed changes

docker run <docker_user_name>/<changes_made>

Current example command to launch docker image / container

docker run -it -v cross:/opt ipatch/debian-lenny-netbsd-git-tmux-jan26-remix /bin/bash

Docker file transfers

To copy some data ie, a file / directory from a docker container to the host OS

docker cp <name_of_docker_container>:/path/to/file /path/on/host/

When copying a directory and all files within the directory from a docker container to the host use a trailing / Example,

docker cp <name_of_docker_container>:/path/to/directory/of/files/ /path/on/host/

Useful Links

TODO

  • build out table of contents for this markdown page.