Operational examples of [docker project]

In [info] production, containers are usually created by dockerfile and docker-compose is used to link containers.

General operating procedures

# Start docker
systemctl start docker
systemctl status docker

# Go to the warehouse and get the mirror first.
docker search ubuntu
docker pull ubuntu
docker images

# Run Mirror Container - dit enters directly without d
docker run --name myubuntu -dit ubuntu /bin/bash

# Look at the boot image, - a displays all (by default only running)
docker ps -a

# Starting container
# If not, docker run-dit Ubuntu at run time
docker start myubuntu

# Enter the container (don't use attach, because if you open another window, it will operate synchronously, similar to single-user remote operation)
docker exec -i -t myubuntu /bin/bash

# View Container Information
docker inspect ac11f587f8c7
docker inspect ac11f587f8c7 | grep IPAddress | cut -d '"' -f 4  # Get ip
docker inspect -f '{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' id   # Get port mapping
docker inspect -f "{{ .State.Pid }}" ac11f587f8c7 # Get pid

# Export container docker save-o [custom image package name] [image]
docker save -o myubuntu2.tar ubuntu

# Stop container
docker stop container_id

# Delete containers (stop before deleting)
docker rm myubuntu

# delete mirror
docker rmi image_id # Or image_name

# Import mirroring
docker load --input centos.tar
docker load < nginx.tar

Running a web-application

docker pull training/webapp

docker run -d -P training/webapp python app.py
# - P maps the network ports used inside the container to the random ports of the host I use. Return container id
# docker port id
# 0.0.0:32769 - > 5000/tcp 5000 port maps to 32769 port of host computer

 # You can also specify ports by - p, where docker port 5000 is mapped to host port 8080
docker run -d -p 8080:5000 training/webapp python app.py

# listener log
docker logs -f b611241d0f01


# Create and pull busybox
docker run -it --name con01 busybox:latest

 # Getting environmental variables
docker exec container_id env

# Kill all running containers
docker kill $(docker ps -q)

# Delete old (created a week ago) containers and note that commands must be single quotes
docker ps -a | grep 'weeks ago' | awk '{print $1}' | sed '1d' | xargs docker rm

# Delete all containers
docker ps -a | awk '{print $1}'| sed '1d' | xargs docker stop | xargs docker rm

# Delete stopped containers
docker rm `docker ps -a -q`

# Delete all mirrors, be careful
docker rmi $(docker images -q)

[info] 1. The container is not a virtual machine, because it is a process. If we quit, the process quits.

  1. If we execute the creation of the container without the image we specified, it will be downloaded from the dockerhub and started.

Tags: Linux Docker Ubuntu Python CentOS

Posted on Wed, 09 Oct 2019 10:47:21 -0700 by MrSarun