docker --link
时间: 2023-12-19 13:03:43 浏览: 30
The `docker --link` command is used to establish a link between two Docker containers. This command allows one container to access the environment variables and network ports of another container.
For example, if you have a web application running in one container and a database running in another container, you can use the `docker --link` command to link the two containers. This will allow the web application to access the database container's environment variables and network ports, making it easier to communicate between the two.
The syntax for the `docker --link` command is as follows:
```
docker run --link <container_name>:<alias> <image_name>
```
Where `<container_name>` is the name of the container you want to link to, and `<alias>` is the name you want to give to the linked container.
For example, if you want to link a web application container named `web` to a database container named `db`, you would use the following command:
```
docker run --link db:database web-app
```
This command would create a new container from the `web-app` image, and link it to the `db` container with the alias `database`. The web application container can now access the database container's environment variables and network ports using the `database` alias.