亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

directory search
Compose About versions and upgrading (Compose) ASP.NET Core + SQL Server on Linux (Compose) CLI environment variables (Compose) Command-line completion (Compose) Compose(組成) Compose command-line reference(組合命令行參考) Control startup order (Compose) Django and PostgreSQL (Compose) Docker stacks and distributed application bundles (Compose) docker-compose build(docker-compose構(gòu)建) docker-compose bundle docker-compose config docker-compose create docker-compose down docker-compose events docker-compose exec docker-compose help docker-compose images docker-compose kill docker-compose logs docker-compose pause docker-compose port docker-compose ps docker-compose pull docker-compose push docker-compose restart docker-compose rm docker-compose run docker-compose scale docker-compose start docker-compose stop docker-compose top docker-compose unpause docker-compose up Environment file (Compose) Environment variables in Compose Extend services in Compose Frequently asked questions (Compose) Getting started (Compose) Install Compose Link environment variables (deprecated) (Compose) Networking in Compose Overview of Docker Compose Overview of docker-compose CLI Quickstart: Compose and WordPress Rails and PostgreSQL (Compose) Sample apps with Compose Using Compose in production Using Compose with Swarm Engine .NET Core application (Engine) About images, containers, and storage drivers (Engine) Add nodes to the swarm (Engine) Apply custom metadata (Engine) Apply rolling updates (Engine) apt-cacher-ng Best practices for writing Dockerfiles (Engine) Binaries (Engine) Bind container ports to the host (Engine) Breaking changes (Engine) Build your own bridge (Engine) Configure container DNS (Engine) Configure container DNS in user-defined networks (Engine) CouchDB (Engine) Create a base image (Engine) Create a swarm (Engine) Customize the docker0 bridge (Engine) Debian (Engine) Default bridge network Delete the service (Engine) Deploy a service (Engine) Deploy services to a swarm (Engine) Deprecated Engine features Docker container networking (Engine) Docker overview (Engine) Docker run reference (Engine) Dockerfile reference (Engine) Dockerize an application Drain a node (Engine) Engine FAQ (Engine) Fedora (Engine) Get started (Engine) Get started with macvlan network driver (Engine) Get started with multi-host networking (Engine) How nodes work (Engine) How services work (Engine) Image management (Engine) Inspect the service (Engine) Install Docker (Engine) IPv6 with Docker (Engine) Join nodes to a swarm (Engine) Legacy container links (Engine) Lock your swarm (Engine) Manage nodes in a swarm (Engine) Manage sensitive data with Docker secrets (Engine) Manage swarm security with PKI (Engine) Manage swarm service networks (Engine) Migrate to Engine 1.10 Optional Linux post-installation steps (Engine) Overview (Engine) PostgreSQL (Engine) Raft consensus in swarm mode (Engine) Riak (Engine) Run Docker Engine in swarm mode Scale the service (Engine) SDKs (Engine) Select a storage driver (Engine) Set up for the tutorial (Engine) SSHd (Engine) Storage driver overview (Engine) Store service configuration data (Engine) Swarm administration guide (Engine) Swarm mode key concepts (Engine) Swarm mode overlay network security model (Engine) Swarm mode overview (Engine) Understand container communication (Engine) Use multi-stage builds (Engine) Use swarm mode routing mesh (Engine) Use the AUFS storage driver (Engine) Use the Btrfs storage driver (Engine) Use the Device mapper storage driver (Engine) Use the OverlayFS storage driver (Engine) Use the VFS storage driver (Engine) Use the ZFS storage driver (Engine) Engine: Admin Guide Amazon CloudWatch logs logging driver (Engine) Bind mounts (Engine) Collect Docker metrics with Prometheus (Engine) Configuring and running Docker (Engine) Configuring logging drivers (Engine) Control and configure Docker with systemd (Engine) ETW logging driver (Engine) Fluentd logging driver (Engine) Format command and log output (Engine) Google Cloud logging driver (Engine) Graylog Extended Format (GELF) logging driver (Engine) Journald logging driver (Engine) JSON File logging driver (Engine) Keep containers alive during daemon downtime (Engine) Limit a container's resources (Engine) Link via an ambassador container (Engine) Log tags for logging driver (Engine) Logentries logging driver (Engine) PowerShell DSC usage (Engine) Prune unused Docker objects (Engine) Run multiple services in a container (Engine) Runtime metrics (Engine) Splunk logging driver (Engine) Start containers automatically (Engine) Storage overview (Engine) Syslog logging driver (Engine) tmpfs mounts Troubleshoot volume problems (Engine) Use a logging driver plugin (Engine) Using Ansible (Engine) Using Chef (Engine) Using Puppet (Engine) View a container's logs (Engine) Volumes (Engine) Engine: CLI Daemon CLI reference (dockerd) (Engine) docker docker attach docker build docker checkpoint docker checkpoint create docker checkpoint ls docker checkpoint rm docker commit docker config docker config create docker config inspect docker config ls docker config rm docker container docker container attach docker container commit docker container cp docker container create docker container diff docker container exec docker container export docker container inspect docker container kill docker container logs docker container ls docker container pause docker container port docker container prune docker container rename docker container restart docker container rm docker container run docker container start docker container stats docker container stop docker container top docker container unpause docker container update docker container wait docker cp docker create docker deploy docker diff docker events docker exec docker export docker history docker image docker image build docker image history docker image import docker image inspect docker image load docker image ls docker image prune docker image pull docker image push docker image rm docker image save docker image tag docker images docker import docker info docker inspect docker kill docker load docker login docker logout docker logs docker network docker network connect docker network create docker network disconnect docker network inspect docker network ls docker network prune docker network rm docker node docker node demote docker node inspect docker node ls docker node promote docker node ps docker node rm docker node update docker pause docker plugin docker plugin create docker plugin disable docker plugin enable docker plugin inspect docker plugin install docker plugin ls docker plugin push docker plugin rm docker plugin set docker plugin upgrade docker port docker ps docker pull docker push docker rename docker restart docker rm docker rmi docker run docker save docker search docker secret docker secret create docker secret inspect docker secret ls docker secret rm docker service docker service create docker service inspect docker service logs docker service ls docker service ps docker service rm docker service scale docker service update docker stack docker stack deploy docker stack ls docker stack ps docker stack rm docker stack services docker start docker stats docker stop docker swarm docker swarm ca docker swarm init docker swarm join docker swarm join-token docker swarm leave docker swarm unlock docker swarm unlock-key docker swarm update docker system docker system df docker system events docker system info docker system prune docker tag docker top docker unpause docker update docker version docker volume docker volume create docker volume inspect docker volume ls docker volume prune docker volume rm docker wait Use the Docker command line (Engine) Engine: Extend Access authorization plugin (Engine) Docker log driver plugins Docker network driver plugins (Engine) Extending Engine with plugins Managed plugin system (Engine) Plugin configuration (Engine) Plugins API (Engine) Volume plugins (Engine) Engine: Security AppArmor security profiles for Docker (Engine) Automation with content trust (Engine) Content trust in Docker (Engine) Delegations for content trust (Engine) Deploying Notary (Engine) Docker security (Engine) Docker security non-events (Engine) Isolate containers with a user namespace (Engine) Manage keys for content trust (Engine) Play in a content trust sandbox (Engine) Protect the Docker daemon socket (Engine) Seccomp security profiles for Docker (Engine) Secure Engine Use trusted images Using certificates for repository client verification (Engine) Engine: Tutorials Engine tutorials Network containers (Engine) Get Started Part 1: Orientation Part 2: Containers Part 3: Services Part 4: Swarms Part 5: Stacks Part 6: Deploy your app Machine Amazon Web Services (Machine) Digital Ocean (Machine) docker-machine active docker-machine config docker-machine create docker-machine env docker-machine help docker-machine inspect docker-machine ip docker-machine kill docker-machine ls docker-machine provision docker-machine regenerate-certs docker-machine restart docker-machine rm docker-machine scp docker-machine ssh docker-machine start docker-machine status docker-machine stop docker-machine upgrade docker-machine url Driver options and operating system defaults (Machine) Drivers overview (Machine) Exoscale (Machine) Generic (Machine) Get started with a local VM (Machine) Google Compute Engine (Machine) IBM Softlayer (Machine) Install Machine Machine Machine CLI overview Machine command-line completion Machine concepts and help Machine overview Microsoft Azure (Machine) Microsoft Hyper-V (Machine) Migrate from Boot2Docker to Machine OpenStack (Machine) Oracle VirtualBox (Machine) Provision AWS EC2 instances (Machine) Provision Digital Ocean Droplets (Machine) Provision hosts in the cloud (Machine) Rackspace (Machine) VMware Fusion (Machine) VMware vCloud Air (Machine) VMware vSphere (Machine) Notary Client configuration (Notary) Common Server and signer configurations (Notary) Getting started with Notary Notary changelog Notary configuration files Running a Notary service Server configuration (Notary) Signer configuration (Notary) Understand the service architecture (Notary) Use the Notary client
characters

  • 1:概況介紹

  • 2:集裝箱

  • 3:服務(wù)

  • 4:成群

  • 5:堆疊

  • 6:部署應(yīng)用程序

先決條件

  • 安裝Docker版本1.13或更高版本...

  • 閱讀第1部分中的方向。

  • 給您的環(huán)境一個(gè)快速測(cè)試運(yùn)行,以確保您已經(jīng)設(shè)置好了:

碼頭經(jīng)營(yíng)哈羅-世界

導(dǎo)言

現(xiàn)在是開(kāi)始以Docker方式構(gòu)建應(yīng)用程序的時(shí)候了。我們將從這種應(yīng)用程序的層次結(jié)構(gòu)的底部開(kāi)始,該應(yīng)用程序是一個(gè)容器,我們將在此頁(yè)面上進(jìn)行介紹。在這個(gè)層次上面是一個(gè)服務(wù),它定義了容器在生產(chǎn)中的行為方式,在第3部分中進(jìn)行了討論。最后,在頂層是堆棧,定義了第5部分中介紹的所有服務(wù)的交互。

  • 堆疊

  • 服務(wù)

  • 集裝箱你在這里

您的新開(kāi)發(fā)環(huán)境

在過(guò)去,如果您要開(kāi)始編寫(xiě)Python應(yīng)用程序,您的首要任務(wù)就是將Python運(yùn)行時(shí)安裝到您的計(jì)算機(jī)上。但是,這就造成了這樣一種情況:為了使應(yīng)用程序按預(yù)期運(yùn)行,計(jì)算機(jī)上的環(huán)境必須是這樣的;運(yùn)行應(yīng)用程序的服務(wù)器也是如此。

使用Docker,您只需獲取一個(gè)可移植的Python運(yùn)行時(shí)作為映像,無(wú)需安裝。然后,您的構(gòu)建可以將基本Python映像與應(yīng)用程序代碼放在一起,確保應(yīng)用程序、其依賴項(xiàng)和運(yùn)行時(shí)都能一起運(yùn)行。

這些便攜式圖像是由稱(chēng)為a的東西定義的Dockerfile。

使用Dockerfile

Dockerfile將定義容器內(nèi)環(huán)境中發(fā)生的事情。在這個(gè)環(huán)境中,對(duì)網(wǎng)絡(luò)接口和磁盤(pán)驅(qū)動(dòng)器等資源的訪問(wèn)是虛擬化的,這與系統(tǒng)的其他部分是隔離的,因此您必須將端口映射到外部世界,并具體說(shuō)明要將哪些文件“復(fù)制”到該環(huán)境。但是,在這樣做之后,您可以預(yù)期您的應(yīng)用程序的構(gòu)建是在Dockerfile無(wú)論在哪里運(yùn)行都會(huì)表現(xiàn)得完全一樣。

Dockerfile

創(chuàng)建一個(gè)空目錄。將目錄(cd)更改為新目錄,創(chuàng)建一個(gè)名為的文件Dockerfile,將以下內(nèi)容復(fù)制并粘貼到該文件中并保存。注意解釋新Dockerfile中每條語(yǔ)句的注釋。

# 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
ADD . /app

# Install any needed packages specified in requirements.txt
RUN pip install -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"]

Dockerfile指我們還沒(méi)有創(chuàng)建的幾個(gè)文件,即app.pyrequirements.txt讓我們創(chuàng)造下一個(gè)。

應(yīng)用程序本身

再創(chuàng)建兩個(gè)文件,requirements.txtapp.py,并將它們放在同一個(gè)文件夾中,Dockerfile這就完成了我們的應(yīng)用程序,正如您所看到的,這個(gè)應(yīng)用程序非常簡(jiǎn)單。當(dāng)以上Dockerfile被塑造成一幅圖像,app.pyrequirements.txt會(huì)因?yàn)檫@個(gè)而出現(xiàn)DockerfileADD命令的輸出。app.py可以通過(guò)HTTP訪問(wèn),這要感謝EXPOSE命令。

requirements.txt

Flask
Redis

app.py

from flask import Flaskfrom redis import Redis, RedisErrorimport osimport socket

# Connect to Redis
redis = 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 disabled</i>"

    html = "<h3>Hello {name}!</h3>" \           "<b>Hostname:</b> {hostname}<br/>" \           "<b>Visits:</b> {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)

現(xiàn)在我們看到了pip install -r requirements.txt安裝用于Python的Flask和Redis庫(kù),應(yīng)用程序打印環(huán)境變量NAME,以及調(diào)用的輸出socket.gethostname()最后,由于Redis沒(méi)有運(yùn)行%28,我們只安裝了Python庫(kù),而沒(méi)有安裝Redis本身的%29,因此我們應(yīng)該期望在這里使用它的嘗試會(huì)失敗并產(chǎn)生錯(cuò)誤消息。

:在容器中檢索容器ID時(shí)訪問(wèn)主機(jī)的名稱(chēng),這就像正在運(yùn)行的可執(zhí)行文件的進(jìn)程ID一樣。

而已!您requirements.txt的系統(tǒng)中不需要Python或其他任何東西,也不會(huì)在您的系統(tǒng)上安裝或運(yùn)行此映像??雌饋?lái)你并沒(méi)有真正用Python和Flask建立一個(gè)環(huán)境,但是你已經(jīng)擁有了。

構(gòu)建應(yīng)用程序

我們已經(jīng)準(zhǔn)備好構(gòu)建這個(gè)應(yīng)用程序了。確保您仍然處于新目錄的頂層。這是什么ls應(yīng)顯示:

$ ls
Dockerfile		app.py			requirements.txt

現(xiàn)在運(yùn)行Build命令。這將創(chuàng)建一個(gè)Docker映像,我們將使用它進(jìn)行標(biāo)記-t所以它有個(gè)友好的名字。

docker build -t friendlyhello .

你的形象在哪里?它在您機(jī)器的本地Docker映像注冊(cè)表中:

$ docker images

REPOSITORY            TAG                 IMAGE ID
friendlyhello         latest              326387cea398

運(yùn)行應(yīng)用程序

運(yùn)行應(yīng)用程序,使用以下方法將機(jī)器的端口4000映射到容器的已發(fā)布端口80-p*

docker run -p 4000:80 friendlyhello

您應(yīng)該會(huì)看到Python正在為您的應(yīng)用提供服務(wù)的通知http://0.0.0.0:80。但是該消息來(lái)自容器內(nèi)部,它不知道你將該容器的端口80映射到4000,從而制作正確的URL http://localhost:4000。

轉(zhuǎn)到Web瀏覽器中的URL,查看網(wǎng)頁(yè)上的顯示內(nèi)容,包括“HelloWorld”文本、容器ID和Redis錯(cuò)誤消息。

您還可以使用curl命令在shell中查看相同的內(nèi)容。

$ curl http://localhost:4000<h3>Hello World!</h3><b>Hostname:</b> 8fc990912a14<br/><b>Visits:</b> <i>cannot connect to Redis, counter disabled</i>

*該端口重新映射為4000:80是為了證明你EXPOSEDockerfile,還有你publish使用docker run -p在后面的步驟中,我們將只將主機(jī)上的端口80映射到容器中的端口80,然后使用http://localhost...

命中CTRL+C在你的終點(diǎn)站辭職。

現(xiàn)在讓我們?cè)诤笈_(tái)以分離模式運(yùn)行該應(yīng)用程序:

docker run -d -p 4000:80 friendlyhello

你得到你的應(yīng)用程序的長(zhǎng)容器ID,然后被踢回你的終端。您的容器正在后臺(tái)運(yùn)行。您還可以看到縮寫(xiě)的容器IDdocker container ls%28并且在運(yùn)行命令%29時(shí)兩者都可以互換工作:

$ docker container ls
CONTAINER ID        IMAGE               COMMAND             CREATED
1fa4ab2cf395        friendlyhello       "python app.py"     28 seconds ago

你會(huì)看到的CONTAINER ID匹配正在進(jìn)行的http://localhost:4000...

現(xiàn)在用docker stop若要結(jié)束該進(jìn)程,請(qǐng)使用CONTAINER ID,就像這樣:

docker stop 1fa4ab2cf395

分享你的形象

為了演示我們剛剛創(chuàng)建的圖像的可移植性,讓我們上傳構(gòu)建的映像并在其他地方運(yùn)行它。畢竟,當(dāng)您想要將容器部署到生產(chǎn)中時(shí),您將需要學(xué)習(xí)如何推送到注冊(cè)表。

注冊(cè)表是存儲(chǔ)庫(kù)的集合,存儲(chǔ)庫(kù)是圖像的集合--有點(diǎn)像GitHub存儲(chǔ)庫(kù),只是代碼已經(jīng)構(gòu)建。注冊(cè)中心上的帳戶可以創(chuàng)建許多存儲(chǔ)庫(kù)。大docker默認(rèn)情況下,CLI使用Docker的公共注冊(cè)表。

:我們?cè)谶@里使用Docker的公共注冊(cè)表,僅僅是因?yàn)樗敲赓M(fèi)的和預(yù)先配置的,但是有許多公共注冊(cè)表可供選擇,您甚至可以使用碼頭受信任登記處...

用您的碼頭ID登錄

如果您沒(méi)有碼頭帳戶,請(qǐng)?jiān)贑loud.docker.com請(qǐng)記下你的用戶名。

登錄到本地計(jì)算機(jī)上的Docker公共注冊(cè)表。

docker login

標(biāo)記圖像

將本地映像與注冊(cè)表上的存儲(chǔ)庫(kù)關(guān)聯(lián)的符號(hào)是username/repository:tag標(biāo)記是可選的,但建議使用它,因?yàn)樗亲?cè)表用于為Docker圖像提供一個(gè)版本的機(jī)制。為上下文提供存儲(chǔ)庫(kù)和標(biāo)記有意義的名稱(chēng),如get-started:part1。這將把圖像放在get-started存儲(chǔ)庫(kù)并將其標(biāo)記為part1...

現(xiàn)在,把它放在一起標(biāo)記圖像。跑docker tag image使用您的用戶名、存儲(chǔ)庫(kù)和標(biāo)簽名,以便圖像將上載到您想要的目的地。該命令的語(yǔ)法是:

docker tag image username/repository:tag

例如:

docker tag friendlyhello john/get-started:part1

跑碼頭形象才能看到你的新標(biāo)記圖像。%28你也可以使用docker image ls.%29

$ docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
friendlyhello            latest              d9e555c53008        3 minutes ago       195MB
john/get-started         part1               d9e555c53008        3 minutes ago       195MB
python                   2.7-slim            1c7128a655f6        5 days ago          183MB...

發(fā)布圖像

將標(biāo)記的圖像上載到存儲(chǔ)庫(kù):

docker push username/repository:tag

一旦完成,這個(gè)上傳的結(jié)果是公開(kāi)的。如果你登錄到碼頭樞紐,您將看到新的圖像,在那里,它的拉命令。

從遠(yuǎn)程存儲(chǔ)庫(kù)中提取并運(yùn)行映像

從現(xiàn)在開(kāi)始,你可以用docker run并使用以下命令在任何機(jī)器上運(yùn)行您的應(yīng)用程序:

docker run -p 4000:80 username/repository:tag

如果映像在機(jī)器上本地不可用,Docker將從存儲(chǔ)庫(kù)中提取它。

docker image rm <image id>
$ docker run -p 4000:80 john/get-started:part1
Unable to find image 'john/get-started:part1' locally
part1: Pulling from orangesnap/get-started
10a267c67f42: Already exists
f68a39a6a5e4: Already exists
9beaffc0cf19: Already exists
3c1fe835fb6b: Already exists
4c9f1fa8fcb8: Already exists
ee7d8f576a14: Already exists
fbccdcced46e: Already exists
Digest: sha256:0601c866aab2adcc6498200efd0f754037e909e5fd42069adeff72d1e2439068
Status: Downloaded newer image for john/get-started:part1 * Running on http://0.0.0.0:80/ (Press CTRL+C to quit)

*如果不指定:tag這些命令的一部分,標(biāo)記為:latest將在構(gòu)建和運(yùn)行映像時(shí)假設(shè)。Docker將使用沒(méi)有指定%28標(biāo)記而運(yùn)行的映像的最后一個(gè)版本,而不一定是最近的映像%29。

不管在哪里docker run執(zhí)行時(shí),它將提取您的圖像以及Python和requirements.txt運(yùn)行你的代碼。所有這些都是在一個(gè)整潔的小包中一起運(yùn)行的,主機(jī)只需要安裝Docker就可以運(yùn)行它了。

第二部分結(jié)論

這一頁(yè)就這么多了。在下一節(jié)中,我們將學(xué)習(xí)如何通過(guò)在服務(wù)...

繼續(xù)第3部分

重述和備忘單%28可選%29

這是本頁(yè)所涵蓋內(nèi)容的終端記錄*

下面列出了這個(gè)頁(yè)面中的基本Docker命令,以及一些相關(guān)的命令,如果您想在繼續(xù)之前進(jìn)行一番探索的話。

docker build -t friendlyname .  # Create image using this directory's Dockerfile
docker run -p 4000:80 friendlyname  # Run "friendlyname" mapping port 4000 to 80docker run -d -p 4000:80 friendlyname         # 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 <hash>           # Gracefully stop the specified container
docker container kill <hash>         # Force shutdown of the specified container
docker container rm <hash>        # 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 <image id>            # 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 <image> username/repository:tag  # Tag <image> for upload to registry
docker push username/repository:tag            # Upload tagged image to registry
docker run username/repository:tag                   # Run image from a registry
Previous article: Next article: