mirror of
https://github.com/docker/cli.git
synced 2026-01-18 08:21:31 +03:00
1.5 KiB
1.5 KiB
- title
- Base commands
- description
- Common usage and commands
- keywords
- Examples, Usage
Base commands
Running an interactive shell
# Download a base image
docker pull base
# Run an interactive shell in the base image,
# allocate a tty, attach stdin and stdout
docker run -i -t base /bin/bashStarting a long-running worker process
# Run docker in daemon mode
(sudo docker -d || echo "Docker daemon already running") &
# Start a very useful long-running process
JOB=$(docker run -d base /bin/sh -c "while true; do echo Hello world; sleep 1; done")
# Collect the output of the job so far
docker logs $JOB
# Kill the job
docker kill $JOBListing all running containers
docker psExpose a service on a TCP port
# Expose port 4444 of this container, and tell netcat to listen on it
JOB=$(docker run -d -p 4444 base /bin/nc -l -p 4444)
# Which public port is NATed to my container?
PORT=$(docker port $JOB 4444)
# Connect to the public port via the host's public address
echo hello world | nc $(hostname) $PORT
# Verify that the network connection worked
echo "Daemon received: $(docker logs $JOB)"Continue to the complete Command Line Interface