Docker 技术学习

Docker 命令
list of container existed
docker container ls
list of running containers
docker ps
list of all containers
docker ps -a
enter container
docker exec -it d27bd3008ad9 /bin/bash
stop all running containers
docker stop $(docker ps -q)
remove all containers
docker rm $(docker ps -aq)
stop and remove containers
docker stop (docker ps -q) & docker rm (docker ps -aq)
清空docker
docker system prune --all
Docker-Orientation, Containers
1.Orientation
List Docker CLI commands
docker docker container --help
Display Docker version and info
docker --version docker version docker info
Execute Docker image
docker run hello-world
List Docker image
docker image ls
List Docker containers (running, all, all in quiet mode)
docker container ls docker container ls -all docker container ls -aq
2.Containers The portable image is define by something called a Dockerfile. Define a container with Dockerfile
Use an official Python runtime as a parent image
FROM python:2.7-slim
Set the working directory to /app
WORKDIR /app
Copy the current directory contents into the container at /app
COPY . /app
Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
Make port 80 available to the world outside this container
EXPOSE 80
Define environment variable
ENV NAME World
Run app.py when the container launches
CMD ["python", "app.py"]
Build the app Create a Docker image. Use -t if you want to use the shorter option. docker build --tag=friendlyhello .
Build image in docer docker image ls Note how the tag defaulted to latest. The full syntax for the tag option would be something like --tag=friendlyhello:v0.0.1.
Run the app Mapping your machine's port 4000 to the container's published port 80 using -p: docker run -p 4000:80 friendlyhello
Stop, remove the container docker container stop docker container rm
Share your image A registry is a collection of repositories, and a repository is a collection of images.
docker build -t friendlyhello . # Create image using this directory's Dockerfile docker run -p 4000:80 friendlyhello # Run "friendlyname" mapping port 4000 to 80 docker run -d -p 4000:80 friendlyhello # Same thing, but in detached mode docker container ls # List all running containers docker container ls -a # List all containers, even those not running docker container stop # Gracefully stop the specified container docker container kill # Force shutdown of the specified container docker container rm # Remove specified container from this machine docker container rm (docker container ls -a -q) # Remove all containers docker image ls -a # List all images on this machine docker image rm # Remove specified image from this machine docker image rm (docker image ls -a -q) # Remove all images from this machine docker login # Log in this CLI session using your Docker credentials docker tag username/repository:tag # Tag for upload to registry docker push username/repository:tag # Upload tagged image to registry docker run username/repository:tag # Run image from a registry
Docker-Services 3.Services About services In a distributed application, different pieces of the app are called “services”. Services are really just “containers in production.” A service only runs one image, but it codifies the way that image runs—what ports it should use, how many replicas of the container should run so the service has the capacity it needs, and so on. Scaling a service changes the number of container instances running that piece of software, assigning more computing resources to the service in the process.
docker-compose.yml
version: "3" service: web: image: jieanyang/get-started:v0.0.1 deploy: replicas: 5 resources: limits: cpus: "0.1" # 10% of the cpu memory: 50M # RAM restart_policy: condition: on-failure ports:
- "4000:80" networks:
- webnet networks: webnet:
Run your new load-balanced app Before we can use the docker stack deploy command we first run: docker swarm init
Now let’s run it. You need to give your app a name. It is set to getstartedlab: docker stack deploy -c docker-compose.yml getstartedlab
Get the service ID for the one service in our application: docker service ls The command lets you view all services associated with the getstartedlab stack: docker stack services getstartedlab A single container running in a service is called a task. List the tasks for your service: docker service ps getstartedlab_web Either way, the container ID changes, demonstrating the load-balancing; with each request, one of the 5 tasks is chosen, in a round-robin fashion, to respond.
Scale the app You can scale the app by changing the replicas value in docker-compose.yml, saving the change, and re-running the docker stack deploy command: docker stack deploy -c docker-compose.yml getstartedlab Docker performs an in-place update, no need to tear the stack down first or kill any containers.
Take down the app and the swarm Take the app down docker stack rm getstartedlab Take down the swarm docker swarm leave --force
docker stack ls # List stacks or apps docker stack deploy -c # Run the specified Compose file docker service ls # List running services associated with an app docker service ps # List tasks associated with an app docker inspect # Inspect task or container docker container ls -q # List container IDs docker stack rm # Tear down an application docker swarm leave --force # Take down a single node swarm from the manager
4.Swarms ?
引用:
Docker Documentation https://docs.docker.com/ Docker Compose 配置文件详解 https://www.jianshu.com/p/2217cfed29d7
控制台,终端,tty,shell等概念的区别 http://minixbeta.github.io/%E5%B7%A5%E5%85%B7/2014/02/28/terminal-shell.html Docker在windows下无法开启伪终端解决方法 https://blog.csdn.net/Bearox/article/details/49281221
Windows 10下Docker使用经验谈 https://www.cnblogs.com/daxnet/p/7719574.html
