Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the method of starting Docker service?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "what is the method of starting Docker service". In daily operation, I believe that many people have doubts about the method of starting Docker service. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "what is the method of starting Docker service?" Next, please follow the editor to study!

The Containers# Dockerfile # # Dockerfile file defines the image environment, workspace, network port, and execute the command # # Use an official Python runtime as a parent imageFROM python:2.7-slim# Set the working directory to / appWORKDIR / app# Copy the current directory contents into the container at / appADD. / app# Install any needed packages specified in requirements.txtRUN pip install-r requirements.txt# Make port 80 available to the world outside this containerEXPOSE 8 Define environment variableENV NAME World# Run app.py when the container launchesCMD ["python" "app.py"] # requirements.txt # # Application dependency # FlaskRedis# app.py # # apply from flask import Flaskfrom redis import Redis RedisErrorimport osimport socket# Connect to Redisredis = Redis (host= "redis", db=0, socket_connect_timeout=2, socket_timeout=2) app = Flask (_ _ name__) @ app.route ("/") def hello (): try: visits = redis.incr ("counter") except RedisError: visits = "cannot connect to Redis Counter disabled "html =" Hello {name}! "\" Hostname: {hostname} "\" Visits: {visits} "return html.format (name=os.getenv (" NAME "," world "), hostname=socket.gethostname (), visits=visits) if _ _ name__ =" _ _ main__ ": app.run (host='0.0.0.0') Port=80) # Host create a new image directory $lsDockerfile app.py requirements.txt# docker command sends instructions to the specified machine The default is native, and you can use the docker-machine env virtual machine docker build-t friendlyname. # Create image using this directory's Dockerfile# registers image to the image registry of machine docker run-p 4000 image 80 friendlyname # Run "friendlyname" mapping port 4000 to 80docker run-d-p 4000 VR 80 friendlyname # Same thing, but in detached mode# runs image In container form docker container ls # List all running containersdocker container ls-a # List all containers Even those not runningdocker container stop # Gracefully stop the specified containerdocker container kill # Force shutdown of the specified containerdocker container rm # Remove specified container from this machinedocker container rm $(docker container ls-a-Q) # Remove all containersdocker image ls-a # List all images on this machinedocker image rm # Remove specified image from this machinedocker image rm $(docker image ls-a-Q) # Remove all images from this machine# to delete image, you need to stop the related containerdocker login # Log in this CLI session using your Docker credentialsdocker tag username/repository:tag # Tag for upload to registry# tag imagedocker push username/repository:tag # Upload tagged image to registry# and publish the tagged image to the Docker account / repository docker run-p 4000 username/repository:tag 80 username/repository:tag # Run image from a registry server Port: service port Service# docker-compose.yml # version: "3" services: web: # replace username/repo:tag with your name and image details image: username/repository:tag deploy: replicas: 5 resources: limits: Cpus: "0.1m" memory: 50m restart_policy: condition: on-failure ports:-"80:80" networks:-webnetnetworks: webnet:# pulls the uploaded image from the registry. # run 5 instances of the image as the calling service web, limiting the use of each instance to a maximum of 10% CPU (across all cores) and RAM of 50MB. # if a failure occurs, restart the container immediately. # Map port 80 on the host to the web80 port. # instructs the web container to share port 80 webnet over a network called load balancing. (internally, the container itself releases the web at a brief port to Port 80. ) # webnet uses the default setting, which is a load-balanced overlay network, to define the network.

Start with service

Docker-compose up$ docker-compose psWARNING: Some services (visualizer, web) use the 'deploy' key, which will be ignored. Compose does not support 'deploy' configuration-use `docker stack deploy` to deploy to a swarm. Name Command State Ports-new2_visualizer_1 npm start Up 0.0.0.0 8080/tcp new2_web_1 8083-> Python app.py Up 0.0.0.0 4003-> 80/tcp

Start with stack

Docker stack ls # List stacks or appsdocker swarm initdocker stack deploy-c docker-compose.yml getstartedlab # Run the specified Compose filedocker service ls # List running services associated with an appdocker service ps getstartedlab_web # List tasks associated with an appcurl 192.168.2.249docker stack rm getstartedlab # Tear down an applicationdocker swarm leave-force # Take down the swarm Docker inspect # Inspect task or containerdocker container ls-Q # List container IDsSwarmsdocker-machine create-driver virtualbox myvm1 # Create a VM (Mac Win7 Linux) docker-machine create-d hyperv--hyperv-virtual-switch "myswitch" myvm1 # Win10docker-machine create-- engine-insecure-registry 192.168.1.112 hyperv-virtual-switch 5000 x-node1dicker-machine lsNAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORSx-master * virtualbox Running tcp://192.168.99.131:2376 v17.09.0-ce x-node1 -virtualbox Running tcp://192.168.99.132:2376 v17.09.0-cedocker-machine env x-master # View basic information about your nodedocker-machine ssh x-master "docker swarm init-- advertise-addr" docker-machine ssh x-master "docker node ls" # List the nodes in your swarmdocker-machine ssh x-master "docker swarm join-token manager" docker-machine ssh x-node1 "docker Swarm join-- token SWMTKN-1-1mw72ip89hsz351lbbhvuj97nj4x5q5vs6zk1zidtcs093isvq-7y6kwg6emzyhokesi7zn7d1qt 192.168.99.131 1mw72ip89hsz351lbbhvuj97nj4x5q5vs6zk1zidtcs093isvq-7y6kwg6emzyhokesi7zn7d1qt 2377 "docker-machine ssh x-master" docker node ls "# List the nodes in your swarmdocker stack deploy-c docker-compose.yml getstartedlab # swarms Open servicedocker stack ps getstartedlabcurl 192.168.2.249curl 192.168.99.131curl 192.168.99.132docker stack rm getstartedlabStacks# docker-compose.yml # version: "3" services: web: # replace username/repo:tag with your name and image details image: username/repo:tag deploy: replicas: 5 restart_policy: condition: on-failure resources: limits: cpus: "0.1" memory: 50m ports: -"80:80" networks:-webnet visualizer: image: dockersamples/visualizer:stable ports:-"8080 volumes: -" / var/run/docker.sock:/var/run/docker.sock "deploy: placement: constraints: [node.role = = manager] networks:-webnetnetworks: webnet:# add stack service to this The study on "what is the method of starting Docker service" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report