あなたが完了した後Dockerのインストール作成の最初のステップをガイドする新しいウィンドウが必要です画像そしてコンテナDockerを使用する場合:
これは、最初のイメージをダウンロードしてコンテナーとして実行する方法を習得するための興味深い方法です。
このアプリに組み込まれている右側のターミナルでコマンドを実行できますが、私は自分のシェルで実行することを好みます。
macOSターミナルを開いて、実行しますcd dev
私の家に入るdev
フォルダ、そして私は作成しますdocker
すべてのDocker実験をホストするサブディレクトリ。走るcd docker
それに入るために、そして私は走ります
git clone https://github.com/docker/getting-started
このコマンドは新しいを作成しましたgetting-started
リポジトリの内容を含むフォルダhttps://github.com/docker/getting-started:
このフォルダから、コマンドを実行しますdocker build
この方法では:
docker build -t docker101tutorial .
これにより、現在のフォルダのコンテンツからタグ名を使用してイメージが作成されます。docker101tutorial
。
これはDockerfileです
*# Install the base requirements for the app.*
*# This stage is to support development.*
FROM python:alpine AS base
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
# Run tests to validate app
FROM node:12-alpine AS app-base
WORKDIR /app
COPY app/package.json app/yarn.lock ./
RUN yarn install
COPY app/spec ./spec
COPY app/src ./src
RUN yarn test
# Clear out the node_modules and create the zip
FROM app-base AS app-zip-creator
RUN rm -rf node_modules &&
apk add zip &&
zip -r /app.zip /app
# Dev-ready container - actual files will be mounted in
FROM base AS dev
CMD [“mkdocs”, “serve”, “-a”, “0.0.0.0:8000”]
# Do the actual build of the mkdocs site
FROM base AS build
COPY . .
RUN mkdocs build
# Extract the static content from the build
# and use a nginx image to serve the content
FROM nginx:alpine
COPY --from=app-zip-creator /app.zip /usr/share/nginx/html/assets/app.zip
COPY --from=build /app/site /usr/share/nginx/html
ご覧のとおり、1つだけでなく、3つのベースイメージからイメージを作成します。python:alpine
、node:12-alpine
そしてnginx:alpine
。
あなたが走るときdocker build -t docker101tutorial .
、最初のベースイメージをダウンロードすることから始まります。
次に、Dockerfileで定義したすべてのコマンドを実行します。
それは私たちが最後に到達するまで続きます:
これで画像ができましたdocker101tutorial
このイメージに基づいてコンテナを実行できます。
コマンドを実行しますdocker run
それらの属性を持つ:
docker run -d -p 80:80 --name docker-tutorial docker101tutorialWe’re using the option -d
to run the container in background and print the container ID. If you miss this flag, you will not immediately get back to the shell until the container exits (but if it’s long-lived, for example it runs a service like a Node app or something, it will not exit automatically).
The -p
option is used to map port 80 of the container to the host machine port 80. The container exposes a Web server on port 80, and we can map ports on our computer to ports exposed by the container.
--name
assigns a name to the container, and finally we have the image name (docker101tutorial
) we should use to create the container.
If you have any doubt about a command option, run docker <command> --help
, in this case docker run --help
and you’ll get a very detailed explanation:

This command is very fast and you’ll get the container ID back:

More docker tutorials:
- Introduction to Docker
- Introduction to Docker Images
- Introduction to Docker Containers
- Dockerfiles
- Installing Docker on macOS
- First steps with Docker after the installation
- Using Docker Desktop to manage a Container
- Create a simple Node.js Hello World Docker Container from scratch
- What to do if a Docker container immediately exits
- Working with Docker Containers from the command line
- Working with Docker Images from the command line
- Sharing Docker Images on Docker Hub
- How to access files outside a Docker container
- How to commit changes to a Docker image
- Updating a deployed container based on a Docker image