docker run
New
Syntax
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Parameters
| Parameters | Description | Examples | Level |
|---|---|---|---|
-d --detach |
docker run -d nginx |
Common | |
-p --publish |
(:) | docker run -p 8080:80 nginx |
Common |
--name |
docker run --name my-app nginx |
Common | |
-e --env |
docker run -e NODE_ENV=production node |
Common | |
-v --volume |
(:) | docker run -v /data:/app/data nginx |
Common |
--rm |
docker run --rm alpine echo hello |
Common | |
-it |
docker run -it ubuntu bash |
Common | |
--network |
docker run --network my-net nginx |
Advanced | |
--restart |
docker run --restart=always nginx |
Advanced |
Examples
Nginx
docker run -d -p 8080:80 --name web nginx
localhost:8080 Nginx
command
docker run --rm alpine cat /etc/os-release
docker run -d -p 3000:3000 -v $(pwd):/app -w /app node:18 npm start
docker run -d -e MYSQL_ROOT_PASSWORD=secret -p 3306:3306 mysql:8
Common Errors
docker: Error response from daemon: Conflict. The container name is already in use, docker rm
docker: Error response from daemon: driver failed programming external connectivity: port is already allocated,
Unable to find image 'xxx' locally, and, docker pull
Tips
- --restart=unless-stopped
- --rm
- -e, --env-file