Simple example of using Docker container

Simple example of using Docker container

1. Pull the image

1. Check if the image exists

[root@node1 ~]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 15187 [OK]       
jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 2048 [OK]
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 816 [OK]
jc21/nginx-proxy-manager Docker container for managing Nginx proxy ho… 218                  
linuxserver/nginx An Nginx container, brought to you by LinuxS… 149                  
tiangolo/nginx-rtmp Docker image with Nginx using the nginx-rtmp… 136 [OK]
jlesage/nginx-proxy-manager Docker container for Nginx Proxy Manager 123 [OK]
alfg/nginx-rtmp NGINX, nginx-rtmp-module and FFmpeg from sou… 102 [OK]
jasonrivers/nginx-rtmp Docker images to host RTMP streams using NGI… 92 [OK]
nginxdemos/hello NGINX webserver that serves a simple page co… 70 [OK]
privatebin/nginx-fpm-alpine PrivateBin running on an Nginx, php-fpm & Al… 56 [OK]
nginx/nginx-ingress NGINX and NGINX Plus Ingress Controllers for… 55                   
nginxinc/nginx-unprivileged Unprivileged NGINX Dockerfiles 45                   
staticfloat/nginx-certbot Opinionated setup for automatic TLS certs lo… 24 [OK]
nginx/nginx-prometheus-exporter NGINX Prometheus Exporter for NGINX and NGIN… 19                   
schmunk42/nginx-redirect A very simple container to redirect HTTP tra… 19 [OK]
centos/nginx-112-centos7 Platform for running nginx 1.12 or building … 15                   
centos/nginx-18-centos7 Platform for running nginx 1.8 or building n… 13                   
raulr/nginx-wordpress Nginx front-end for the official wordpress:f… 13 [OK]
bitwarden/nginx The Bitwarden nginx web server acting as ar… 11                   
flashspys/nginx-static Super Lightweight Nginx Image 10 [OK]
mailu/nginx Mailu nginx frontend 9 [OK]
sophos/nginx-vts-exporter Simple server that scrapes Nginx vts stats a… 7 [OK]
ansibleplaybookbundle/nginx-apb An APB to deploy NGINX 2 [OK]
wodby/nginx Generic nginx 1

2. Pull and download the image

[root@node1 ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
b4d181a07f80: Pull complete 
66b1c490df3f: Pull complete 
d0f91ae9b44c: Pull complete 
baf987068537: Pull complete 
6bbc76cbebeb: Pull complete 
32b766478bc2: Pull complete 
Digest: sha256:353c20f74d9b6aee359f30e8e4f69c3d7eaea2f610681c4a95849a2fd7c497f9
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

3. View local image

[root@node1 ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 4cdc5dd7eaad 2 weeks ago 133MB

2. Run the image

1. Install related packages

[root@node1 ~]# yum install -y libseccomp-devel 
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Repository AppStream is listed more than once in the configuration
Repository AppStream is listed more than once in the configuration
Repository BaseOS is listed more than once in the configuration
Repository AppStream is listed more than once in the configuration
Repository BaseOS is listed more than once in the configuration
Docker CE Nightly - Sources 798 B/s | 2.3 kB 00:02    
ansiable 0.0 B/s | 0 B 00:00    
Failed to synchronize cache for repo 'docker-ce-nightly-source', ignoring this repo.
Failed to synchronize cache for repo 'ansiable', ignoring this repo.
Last metadata expiration check: 2:32:21 ago on Wed 21 Jul 2021 07:51:23 PM CST.
Dependencies resolved.
===============================================================================================================================================
 Package Arch Version Repository Size
===============================================================================================================================================
Installing:
 libseccomp-devel x86_64 2.5.1-1.el8 AppStream 57k
Upgrading:
 libseccomp x86_64 2.5.1-1.el8 base 71 k

Transaction Summary
===============================================================================================================================================
Install 1 Package
Upgrade 1 Package

Total download size: 128 k
Downloading Packages:
(1/2): libseccomp-2.5.1-1.el8.x86_64.rpm 256 kB/s | 71 kB 00:00    
(2/2): libseccomp-devel-2.5.1-1.el8.x86_64.rpm 186 kB/s | 57 kB 00:00    
-----------------------------------------------------------------------------------------------------------------------------------------------
Total 414 kB/s | 128 kB 00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing: 1/1 
  Upgrading: libseccomp-2.5.1-1.el8.x86_64 1/3 
  Running scriptlet: libseccomp-2.5.1-1.el8.x86_64 1/3 
  Installing: libseccomp-devel-2.5.1-1.el8.x86_64 2/3 
  Cleanup: libseccomp-2.3.3-3.el8.x86_64 3/3 
  Running scriptlet: libseccomp-2.3.3-3.el8.x86_64 3/3 
  Verifying : libseccomp-devel-2.5.1-1.el8.x86_64 1/3 
  Verifying : libseccomp-2.5.1-1.el8.x86_64 2/3 
  Verifying : libseccomp-2.3.3-3.el8.x86_64 3/3 
Installed products updated.

Upgraded:
  libseccomp-2.5.1-1.el8.x86_64                                         

Installed:
  libseccomp-devel-2.5.1-1.el8.x86_64                                                                                                         
Complete!

2. Generate container

Note: - d runs the container in the background -p 80:80 port mapping host port: container port
[root@node1 ~]# docker run -d -p 80:80 nginx
2716e3ec14173a31d8c2168ceceefbbfecec0efe6d611bc710df0bc53748ef0c

3. Check the running status of the container

[root@node1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2716e3ec1417 nginx "/docker-entrypoint.…" 26 seconds ago Up 24 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp naughty_driscoll

3. Test the application in the container

insert image description here

4. Check the host port

[root@node1 ~]# netstat -tunlp |grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3807/docker-proxy   
tcp6 0 0 :::80 :::* LISTEN 3814/docker-proxy   
tcp6 0 0 :::8081 :::* LISTEN 1092/httpd

5. Stop the container

[root@node1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2716e3ec1417 nginx "/docker-entrypoint.…" 6 minutes ago Up 6 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp naughty_driscoll
[root@node1 ~]# docker stop 2716e3ec1417 
2716e3ec1417
[root@node1 ~]# docker start 2716e3ec1417 
2716e3ec1417

This concludes this article about a simple example of how to use Docker containers. For more information on using Docker containers, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Implementation of Docker Compose container orchestration in IDEA
  • Docker Tutorial: Using Containers (Simple Example)
  • Docker container uses Jenkins to deploy web projects (summary)
  • How to use Mysql in Tomcat container under Docker
  • Detailed explanation of how to view the resources used by Docker containers

<<:  Basic principles for compiling a website homepage

>>:  Detailed explanation of Vue components

Recommend

Common shell script commands and related knowledge under Linux

Table of contents 1. Some points to remember 1. V...

Nofollow makes the links in comments and messages really work

Comments and messages were originally a great way...

Detailed explanation of where the image pulled by docker is stored

20200804Addendum: The article may be incorrect. Y...

Detailed explanation of the usage and difference between nohup and & in Linux

Example: We use the Python code loop_hello.py as ...

CSS3 uses var() and calc() functions to achieve animation effects

Preview knowledge points. Animation Frames Backgr...

JS implements a detailed plan for the smooth version of the progress bar

The progress bar is not smooth I believe that mos...

How to configure Jupyter notebook in Docker container

Jupyter notebook is configured under the docker c...

JavaScript implements circular progress bar effect

This article example shares the specific code of ...

Analysis of implicit bug in concurrent replication of MySQL 5.7

Preface Most of our MySQL online environments use...

Docker deploys mysql remote connection to solve 2003 problems

Connecting to MySQL Here I use navicat to connect...

Introduction to Sublime Text 2, a web front-end tool

Sublime Text 2 is a lightweight, simple, efficien...

JS uses clip-path to implement dynamic area clipping function

background Today, I was browsing CodePen and saw ...

Vue.js manages the encapsulation of background table components

Table of contents Problem Analysis Why encapsulat...

Let’s talk in detail about how JavaScript affects DOM tree construction

Table of contents Document Object Model (DOM) DOM...

MySQL 8.0.13 download and installation tutorial with pictures and text

MySQL is the most commonly used database. You mus...