Docker Engine - yenbohuang/techNotes GitHub Wiki

Install Docker CE

Docker + Consul + Swarm + Registrator + Nginx

These blog posts (from part 1 to 4) introduce about how to use "Docker + Consul + Swarm + Registrator + Nginx" for blue-green deployment:

Verify docker installation

See if this command works.

docker run hello-world

See details on https://docs.docker.com/linux/step_one/

Run a docker image

docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

List all docker images

docker images

See details on https://docs.docker.com/linux/step_three/

See which docker containers are ran

docker ps 

See details on https://docs.docker.com/engine/tutorials/dockerizing/

Display live status for docker containers

#!/bin/sh
while [ 1=1 ]
do
  clear
  docker images | grep -v none
  docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Command}}\t{{.RunningFor}}\t{{.Status}}"
  echo "Refreshed every 5 seconds....$(date)"
  sleep 5
done

See details on https://docs.docker.com/engine/reference/commandline/ps/

Display logs in a container

docker logs -f <container name>

See details on https://docs.docker.com/engine/tutorials/dockerizing/

List running process in a container

docker top <container name>

See details on https://docs.docker.com/engine/tutorials/usingdocker/

Inspect container

docker inspect <container name>

See details on https://docs.docker.com/engine/tutorials/usingdocker/

Open a shell in running container

docker exec -it <container name> /bin/sh

See details on https://docs.docker.com/engine/tutorials/networkingcontainers/

Stop a running container

docker stop <container name>

See details on https://docs.docker.com/engine/tutorials/usingdocker/

Clean up local environments

Kill all running containers

docker kill $(docker ps -aq)

Delete all containers

docker rm $(docker ps -aq)

Delete all images

docker rmi -f $(docker images -aq)

Export files in docker container into a tarball

  • Get container ID by the following command:
docker container ls -l
  • Export to tarball
docker export <container iD> -o my.tar

Pull docker image from Nexus

{
  "insecure-registries" : ["<Nexus IP>:<Nexus Port>"]
}
  • You must restart docker engine to pick up config.
sudo service docker restart
  • Login docker
    • Remember adding port number, or CLI will use 443 (default) port number.
docker login <Nexus IP>:<Nexus port>
  • See of it works
docker run <Nexus IP>:<Nexus Port>/hello-world
  • Remember adding "gitlab" in front of "gitlab-ce" because it's tag name is "gitlab/gitlab-ce"
docker pull <Nexus IP>:<Nexus Port>/gitlab/gitlab-ce 
  • TODO: Fix this issue later
WARNING! Your password will be stored unencrypted in /home/yenbohuang/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Scanning local image vulnerabilities

Login docker hub by docker login command and run the following:

docker scan <image name>
⚠️ **GitHub.com Fallback** ⚠️