Moment For Technology

【Docker series 】 Docker learning three, Docker preliminary actual combat and Docker visual management tool trial

Posted on Dec. 3, 2022, 9:51 a.m. by Kenneth Smith
Category: The back-end Tag: The back-end docker

This is the fifth day of my participation in the August More text Challenge. For details, see:August is more challenging

【Docker series 】 Docker study 3

Deploy nginx using Dcoker

Search for nginx images

  • Use Docker Search nginx
# docker search nginxNAME DESCRIPTION STARS OFFICIAL AUTOMATED nginx Official build of Nginx. 15246 [OK] jwilder/nginx-proxy Automated Nginx Reverse Proxy for Docker Con... 2053 [OK] Richarvey /nginx-php-fpm Container running nginx + php-fpm capable of running... 2053 [OK] Richarvey /nginx-php-fpm Container running Nginx + php-fpm capable of running... 815 [OK] ...Copy the code
  • Or search for nginx on DockerHub, the specific version and details will be more comprehensive, generally use the official version

Pull the Nginx image

Pull the nGINx image. In this case, pull the latest version of Nginx

# docker pull nginxUsing default tag: latest # Latest: Pulling from library/nginx # Dbb907d5159d: Pull complete 8a268F30C42a: Pull complete B10CF527A02D: Pull complete b10cf527A02D Pull complete c90b090c213b: Pull complete 1f41b2f2bf94: Pull complete Digest: Sha256:8 # f335768880da6baf72b70c701002b45f4932acae8d574dedfddaf967fc3ac90 signature Status: Downloaded newer image for nginx: latest docker. IO/library/nginx: download latest # nginx true pathCopy the code

Create and run the container

  • Create a new container and call it nginx1
  • The default port of nginx is 80, which maps port 80 in docker to port 8888 in host
  • Set up the nginx container to run in the background
# docker run -d --name nginx1 -p 8888:80 nginx

# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2772A4050157 nginx "/ docker-entryPoint...." 2 seconds ago Up 2 seconds TCP nginx1Copy the code


Use the curl command to check whether port 8888 is OK

# curl localhost:8888! DOCTYPE html html head titleWelcome to nginx! /title style body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } /style /head body h1Welcome to nginx! /h1 pIf you see this page, the nginx web server is successfully installed and working. Further configuration is required./p pFor online documentation and support please refer to a href="" Commercial support is available at a href="" pemThank you for using nginx./em/p /body /htmlCopy the code

We can also go into the Nginx Docker container and access port 80 directly

# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2772A4050157 nginx "/ docker-entryPoint...." 14 minutes ago Up 14 minutes TCP NginX1 enters the nGINX1 terminal# docker exec -it nginx1 /bin/bashAccessing Port 80# curl localhost:80
Copy the code


When we created the nginx1 container, we mapped port 8888 of the host to port 80 of the nginx1 container, so we can access port 8888 of the host to port 80 of the nginx1 container

At this point, I can access port 8888 of my Ali Cloud server, which is actually the Nginx server in my nginX1 container

Try using and deploying the visual Docker page Portainer

Portainer is Docker's graphical page management tool, which provides a background panel for us to operate and manage.

Create and start the Portainer

docker run -d -p 8888:9000 --restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer
Copy the code

Optional parameters are as follows:

  • --restart

What is the restart policy when the container exits? Always, default is "no".

  • -v

Bind the attached volume

  • --privileged

Grant extended permissions to this container

  • -p 8888:9000

The 9000 port in the container is mapped to the 8888 port of the host, so that we can access the 9000 port of the portainer container when accessing the 8888 port of the host

Access and set the Portainer user

Browser access: IP:8888

To set the password, click Create Users to see the following page

Explain where the red lines are drawn above:

  • 0 stacks

Stacks are a group of related services that run consistently

  • 1 container

1 container

  • 1 volume

One volume is to be attached

  • 3 images

Three mirror

We went to the mainframe to check docker's system information

docker info
Copy the code

Go to our own Docker service and see each of the items explained above

Let's click on images to see how it looks:

We can see the details of the three images in our Docker service in this web management page, and we can also delete, create, import and export the images

If you are interested, you can familiarize yourself with and try the use of portainer. In the future, we will use Rancher when we do CI/CD

As you learn, you can communicate, practice, read the help document, or use the -help command line to see what parameters are available. For example:

docker run --help

Docker run [parameter] image [command] [parameter list of command...]

Run a command in a new container


-a, --attach list Attach to STDIN, STDOUT or STDERR

-c, --cpu-shares int CPU shares (relative weight)

-d, --detach Runs the container in the background

-e, --env list Sets environment variables

-h, --hostname string Container host name

-i, --interactive Keep STDIN open even if not attached

-l, --label list Set meta data on a container

-m, --memory bytes Indicates the memory limit

-p, --publish list Publish a container's port(s) to the host

-P, --publish-all Publish all exposed ports to random ports

-t, --tty Allocate a pseudo-TTY

-u, --user String User name or UID

-v, --volume list Mounts volumes

-w, --workdir string Sets the working directory in the container


docker docs

Welcome to like, follow and collect

Dear friends, your support and encouragement are the motivation for me to keep sharing and improve the quality

All right, that's it for this time

Technology is open, our mentality, should be more open. Embrace change, live in the sun, and strive to move forward.

I am nezha, welcome to like the collection, see you next time ~

About (Moment For Technology) is a global community with thousands techies from across the global hang out!Passionate technologists, be it gadget freaks, tech enthusiasts, coders, technopreneurs, or CIOs, you would find them all here.