The run command creates a container from an image on the virtual host and calls the entrypoint script.
This command is called the first time for the container creation. You will call start the next time to start it.
docker run hello-world
Hello from Docker!
To generate this message, Docker took the following steps:
docker run -t -i ubuntu /bin/bash
root@af8bae53bdd3:/#
docker run ubuntu /bin/echo 'Hello world'
where:
The container will run in the background giving you back the terminal prompt.
docker run -d ubuntu /bin/sh -c "while true; do echo hello world; sleep 1; done"
3e3a1ac2c76e447542b99de6db704629e414a674301c520687a7dc13a841746d
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3e3a1ac2c76e ubuntu "/bin/sh -c 'while tr" 39 seconds ago Up 39 seconds jolly_panini
where:
You can apply policies 1) to start container automatically when the docker application starts.
docker run -d --restart unless-stopped containerName
docker update --restart no containerName
Create a container and start it
docker run -t -i -d -P \\
--name containerName \\
--rm \\ # To remove the created container (handy)
-v "$(pwd)"/hostPath:/dockerContainerPath \
image \\
command
docker run -t -i -d -P \\
--name containerName \\
--rm \\ # To remove the created container (handy)
-v ${PWD}\hostPath:/dockerContainerPath \
image \\
command
docker run -t -i -d -P \\
--name containerName \\
--rm \\ # To remove the created container (handy)
-v %CD%\hostPath:/dockerContainerPath \
image \\
command
where:
When trying to run a container, you may get this error in a shell:
docker: An error occurred trying to connect: Post http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/containers/create: open //./pipe/docker_engine: The system cannot find the file specified..
See 'docker run --help'.
This is due to Docker OS environment not set.
To resolve this problem,
@FOR /f "tokens=*" %i IN ('docker-machine env default') DO @%i
the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'
When running docker as cron job or programmatically, don't use the interactive option -it