Getting Started with Docker (MAC Environment)-Part 2 container (container)

Source: Internet
Author: User
Tags docker ps docker run

Part-2 container (Container) Introduction

The Docker architecture has three levels, from high to low as follows:

    • Stack (Stack)
    • Services (Service)
    • Containers (Container)

These are now exposed in the layer of the container, similar to the underlying foundation; the service is what functions/services are implemented on this basis; higher-level stacks define some of the interactions within these services.

Benefits of Docker

The development of a thing in the past, after the development of the machine to the server to deploy, related to the configuration of various environments, a variety of software-dependent installation, very troublesome; Docker is equivalent to providing a class of container services, packing these things up, providing standard service, you carry containers to this ship, that pier, He can be put there to provide good service; To pack these things, of course, configuration is required, and the configuration file is called Dockerfile; that is: Dockerfile determines the environment in the container, and this environment is isolated from the system environment.

Docker example
    1. Create a Dockerfile file under a folder with the following contents:
# 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 --trusted-host pypi.python.org -r requirements.txt# Make port 80 available to the world outside this containerEXPOSE 80# Define environment variableENV NAME World# Run app.py when the container launchesCMD ["python", "app.py"]
    1. Create Requirements.txt and app.py files, respectively, with the contents of
FlaskRedis
  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 = "<i>cannot Connect to Redis, counter dis abled</i> "html ="  
    1. Compile (build),docker build -t friendlyhello .
    2. Run the app,docker run -p 4000:80 friendlyhello
    3. View docker image ls , you can see Friendlyhello this image
    4. Browser Access localhost:4000, you can see the app we wrote with Flask
    5. You can use the background mode to start the app, and the command isdocker run -d -p 4000:80 friendlyhello
    6. Background mode-enabled apps can be used docker container stop container_id to turn off
    7. Look at the containers that Docker is running, docker ps and ps like Linux, you can add -a parameters to view all
Share Docker Images

git corresponds to have github,docker corresponding to have Dockerhub, register a Dockerhub account first, then can share;

    1. docker loginLogin account
    2. docker tag imageTo hit the label, similar todocker tag friendlyhello wang/get-started:part2
    3. docker push username/repository:tag, to push the mirror
    4. Pull and then run the mirrordocker run -p 4000:80 username/repository:tag

Getting Started with Docker (MAC Environment)-Part 2 container (container)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.