Docker implements container port binding local port

Docker implements container port binding local port

Today, I encountered a small problem that after starting the image, I could not access it through HTTP request. Let's record and share the solution:

Common Docker startup commands and solutions are as follows:

1. Start Docker

As we all know, the command to start the container is as follows:

docker run image name

2. Binding container ports to local ports

After starting the container, the local port cannot be directly accessed, so it is necessary to bind the local port to the container port so that the container can be accessed through the local port. The settings are as follows:

docker run -p local port: container port image name

Then you can access the container through the local port through the local browser.

3. The container runs in the background, add the -d parameter, the command is as follows:

docker run -d -p local port: container port image name

4. View the mirror list, the command is as follows

docker image ls
or docker images

5. View the running container, the command is as follows

docker ps

Supplement: Docker maps local ports to running containers

1. Submit the running container as an image (so that various operations in the container will not be lost)

docker commit tang tang1
### tang (name of running container) tang1 (name of generated image)

2. Run the image and add ports

docker run -d -it -p 8000:80 tang1:latest /bin/bash
### The small p is the custom port and latest is the label of the image (it is better to write something professional)

Supplement: Docker loads volume and binds port

Require

The docker image has been obtained. Now you want to create a container, load the local directory into the container directory, and map the ports between the local and container.

Specific examples are as follows:

image ID: 884e0fc83dfe

Set container name: test

Map the local port 9000 to the container's port 80

Load the data volume volume: map the local ~/Desktop/test to the container's /test directory

accomplish

docker run -it --name test -v ~/Desktop/test:/test -p 9000:80 884e0fc83dfe /bin/bash
# Enter the new container
docker start test
docker attach test

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. If there are any mistakes or incomplete considerations, please feel free to correct me.

You may also be interested in:
  • Use non-root users to execute script operations in docker containers
  • Solution to the Docker container not having permission to write to the host directory
  • Solve the problem of setting Chinese language pack for Docker container
  • Solution for Docker container not recognizing fonts such as Songti
  • Docker win ping fails container avoidance guide
  • How to configure Jupyter notebook in Docker container
  • Solve the problem of the container showing Exited (0) after docker run
  • Docker uses root to enter the container

<<:  CSS menu button animation

>>:  Detailed explanation of loop usage in javascript examples

Recommend

Kali Linux Vmware virtual machine installation (illustration and text)

Preparation: 1. Install VMware workstation softwa...

Sharing experience on the priority of CSS style loading

During the project development yesterday, I encoun...

Detailed description of the life cycle of React components

Table of contents 1. What is the life cycle 2. Lo...

Six-step example code for JDBC connection (connecting to MySQL)

Six steps of JDBC: 1. Register the driver 2. Get ...

Html to achieve dynamic display of color blocks report effect (example code)

Use HTML color blocks to dynamically display data...

js to achieve star flash effects

This article example shares the specific code of ...

How to implement html input drop-down menu

Copy code The code is as follows: <html> &l...

Implementation of CSS linear gradient concave rectangle transition effect

This article discusses the difficulties and ideas...

onfocus="this.blur()" is hated by blind webmasters

When talking about the screen reading software op...

An article to understand the execution process of MySQL query statements

Preface We need to retrieve certain data that mee...

Implementation of the Pycharm installation tutorial on Ubuntu 18.04

Method 1: Download Pycharm and install Download a...

Use IISMonitor to monitor web pages and automatically restart IIS

Table of contents 1. Tool Introduction 2. Workflo...

Example of how nginx implements dynamic and static separation

Table of contents Deploy nginx on server1 Deploy ...

Summary of three methods of lazy loading lazyLoad using native JS

Table of contents Preface Method 1: High contrast...

Nine advanced methods for deduplicating JS arrays (proven and effective)

Preface The general methods are not listed here, ...