Click here to view code image
$ docker container logs a583eac3cadb
root@a583eac3cadb:/# ps
PID TTY TIME CMD
1 pts/0 00:00:00 bash
11 pts/0 00:00:00 ps
root@a583eac3cadb:/# uname
Linux
Now that you know the basics on launching a container,
the next step is to make it accessible to the rest of the
world. To do this, you can start by pulling an nginx web
server container and assigning it ports to use with the -p
flag. This flag requires that you map the container port to
a free port on the Docker host. If you don’t assign one to
your local host, Docker will pick a random port above
- In addition, you want to make your nginx
container stay running in the background instead of just
quitting after you launch it. By using the -d flag, you can
detach the container and leave it running in the
background. The last thing you can try is to give the
container a name with the --name flag. This way, you
can refer to it by name instead of by using the random
one Docker assigns or the container ID:
Click here to view code image
$ docker container run --name test-nginx -p 80:80
-d nginx
dfe3a47945d2aa1cdc170ebf0220fe8e4784c9287eb84ab0bab7048307b602b9
After the container is launched, you can see it running by
using the ls command, get information on what port it is
using (port 80), and see that the container is mapped to
the local host IP address (referenced by 0.0.0.0):
Click here to view code image
$ docker container ls