Docker Notes
Docker Notes
=================================
Starting DOCKER
================
- install using the following script:
curl -sSL https://get.docker.com/ | sh
systemctl enable docker
systemctl start docker
start image/restart
==========================
docker run <image>:<tag> <application> <values>
docker run -d <image:tag> <function such as bin/bash> (run a function in detached
mode)
docker run -d --name=<name for container> <image:tage> (names must be unique)
docker restart <name or id> (restarts a container)
docker start <id or name> (starts a stopped container)
detail on image
=============================
docker inspect <image>
connect to a container
=======================================
docker run -it centos:latest /bin/bash (logs into interactive mode on current
terminal in bash)
Stop a container
=======================================
docker stop <id or name> (stops a docker container)
Attach to a container
=======================================
docker attach <conatiner name> (attach joins the container process so exitting can
kill the container)
docker exec <command> (executes something in a container without affecting process
started during container instantiation)
e.g. docker exec -it LifeCycle1 /bin/bash
remove image
========================================
docker rmi <repositor:tag or imageid> (will error if stopped or running containers
with this image exist)
docker rmi -f <repositor:tag or imageid> (forces a remove but runnign containers
will continue to run as they have the base image)
docker rm <container id or name> (removes container completely)
docker rm `docker ps -a -q` (removes all non running containers)
redirect port
==========================================
docker run -d --name=<name> -P <image:tag>
docker run -d --name=<name> -p 8080:80 <image:tag>
docker volume
============================================
docker run -d --name=<name> -p <port external>:<port internal> -v <mount a host
directory>:<container directory>
dockerfile
===========================================
based off docker image
usually named Dockerfile
Format:
FROM debian:stable
MAINTAINER test123 <[email protected]>
docker logs
==========================
docker logs <uuid or name>
Docker Network
====================================
docker network ls (shows host networks)
docker network inspect <network id> (show information about the network)
docker network create --subnet 10.1.0.0/24 --gateway 10.1.0.1 mybridge01
docker network rm mybridge01
docker network create --subnet 10.2.0.0/16 --gateway 10.2.0.1 --ip-
range=10.2.4.0/24 --driver=bridge --label=host4network bridge04
docker run -it --name nettest1 --net bridge04 centos:latest /bin/bash
docker run -it --name nettest2 --net bridge04 --ip 10.2.4.100 centos:latest
/bin/bash
docker rename
---------------------------------
docker rename <old name or id> <new name>
Docker events
=============================
docker events --since '<time such as 1h>'
docker events (shows events as they happen)
docker events --filter <opttions include
container/event/images/labe/type/network/daemon>
eg docker events --filter event=attach
Docker history
=========================
docker history <image name>:<id>
docker history --quiet --no-trunc <image name>:<id> (shows the sha key for the
image)
docker tag
=========================
docker tag <image id or name and tag> <image name>:<new tag>
docker hub
==================
docker login
docker logout
docker push <name + tag or id>