The first step to use Docker after installation

after finishingDocker installationYou should have a new window that will guide you through the first steps of creationimagewithContainerUse Docker:

This is an interesting way to help you quickly download the first image and run it as a container.

You can run commands in the built-in terminal on the right side of this application, but I prefer to run it in my own shell.

I open the macOS terminal and runcd devCome into my housedevFolder and then create adockerThe subdirectory where I will host all Docker experiments. I runcd dockerEnter it and then I run

git clone

This command creates a newgetting-startedFolder containing the contents of the repository

Now run the command from that folderdocker buildsuch:

docker build -t docker101tutorial .

This will build the image based on the contents of the current folder you are in, and use the tag namedocker101tutorial.

This is the Dockerfile

*# Install the base requirements for the app.*
*# This stage is to support development.*
FROM python:alpine AS base
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

# Dev-ready container - actual files will be mounted in FROM base AS dev CMD [“mkdocs”, “serve”, “-a”, “”]

# 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 / /usr/share/nginx/html/assets/ COPY --from=build /app/site /usr/share/nginx/html

As you can see, it not only creates images based on one image, but also based on 3 basic images:python:alpine,node:12-alpinewithnginx:alpine.

When you rundocker build -t docker101tutorial ., It will download the first base image first:

Then it will run all the commands we defined in the Dockerfile.

It continues until we reach the end:

Now we have the imagedocker101tutorialWe can run a container based on this image.

Run commanddocker runHas these attributes:

docker run -d -p 80:80 --name docker-tutorial docker101tutorial

We’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: