The docker exec command
The docker exec
command provides the much-needed help to users, who are deploying their own web servers or have other applications running in the background. Now, it is not necessary to log in to run the SSH daemon in the container.
- First, create a Docker container:
$ sudo docker run --name trainingapp \ training/webapp:latest Unable to find image 'training/webapp:latest' locally latest: Pulling from training/webapp 9dd97ef58ce9: Pull complete a4c1b0cb7af7: Pull complete Digest: sha256:06e9c1983bd6d5db5fba376ccd63bfa529e8d02f23d5079b8f74a616308fb11d Status: Downloaded newer image for training/webapp:latest
- Next, run the
docker ps -a
command to get the container ID:
$ sudo docker ps -a a245253db38b training/webapp:latest "python app.py"
- Then, run the
docker exec
command to log in to the container:
$ sudo docker exec -it a245253db38b bash root@a245253db38b:/opt...