--You can create an environment with just a configuration file and commands. --Deployment that includes application and execution environment is Docker style --Advantages of using Docker --Environmental troubles can be minimized --Idempotence can be maintained --The same result is guaranteed no matter how many times you execute it.
--What is a Docker image? --Templates for embodying containers
$ docker image pull gihyodocker/echo:latest #Get the image
$ docker container run -t -p 9000:8080 #Container execution
$ curl http://localhost:9000/ #Try to access
$ docker stop $(docker container ls -q) #Stop
$ docker container stop $(docker container ls --filter "ancestor=example/echo" -q) #Stop
$ docker image build -t example/echo:latest . #Create docker image
$ docker image ls #Check docker image
$ docker container run -p 9000:8080 example/echo:latest #Port forwarding
--Operations for Docker --It can be roughly divided into two types: images and containers.
--"Build a Docker image"
$ docker image --help #See help
$ docker search --limit 5 mysql #Search for
--imaegeID also serves as a version number
--latest
is the master
branch of Git
$ docker image tag example/echo:latest example/echo:0.1.0 #Tag a specific point with a version name, etc.
--Three states of execute, stop, and discard
$ docker container run -t -d --name gihyo-echo example/echo:latest #Create a named container (useful during development)
$ docker container run -it alpine:latest #A terminal is displayed and you can enter characters. You can use it as if you logged in to a virtual environment.
$ docker container ls -q #Extract only the container ID
$ docker container ls --filter "name=echo1" #Filter by name
$ docker container ls -a #Include finished container
$ docker container rm f66f6f2013da #Destroy the container
$ echo '{"version":100}' | docker container run -i --rm gihyodocker/jq:1.5 '.version' #The container you need only then--Immediately destroy with rm
$ docker container logs -f &(docker container ls --filter "ancestor=jenkins" -q) #View log
$ $ docker container exec -it echo sh #Execute command in container
$ docker container cp echo:/echo/main.go . #Copy what's in the container
$ docker container cp dummy.txt echo:/tmp #Copy to container
$ docker container prune #Bulk delete containers that are not running
$ docker image prune #Bulk delete images that are not running
$ docker container stats #View resource usage on a container-by-container basis
docker-compose.yml
version: "3"
services:
echo:
image: example/echo:latest
ports:
- 9000:8080
$ docker-compose up -d #Start-up
$ docker-compose down #Stop
$ docker-compose up -d --build #Build every time and start behind the scenes
$ docker-compose ps #Confirm startup
--Share volume
, not copy
――Docker is a container-based separation of application and infrastructure. --One concern for one container --"Hello! Is output every 1 minute" etc. --Are there any side effects when duplicated as a replica? --Docker's portability limits --CPU architecture and OS assumptions --Dynamic link issues --Control the behavior of the application with environment variables
Create a TODO app with Swarm
$ docker container run -v ${PWD}:/root ch04/tododb:latest
So far for the time being.
Recommended Posts