Wednesday, January 1, 2020

Docker Commands

>docker ps
     list running containers (processes inside of docker) (docker status) (list of running apps)

>docker start/stop [first 3 chars of id, or all of it] or [name]

>docker run hello-world
    I didn't download it, but it automatically downloads it and starts it

>docker run -p 8081:80 nginx
    downloads and runs this web server on localhost:8081

>docker run -p 4000:4000 docs/docker.github.io
     gives you a local docs at localhost:4000, same as http://docs.docker.com/

>docker run -p 4000:4000 -it --name docs docs/docker.github.io
    --it is for interactive terminal which makes your command prompt able to kill the process (docker stop) when pressing ctrl-c.

>docker ps -a
     view all installed containers and their run status

>docker images
     view all downloaded images

View containers that are stopped (not visible using ps command):
>docker container ls -a

Use CLI window to view files in a running container:
>docker exec -it [container name] cmd
     this will give you a cmd prompt at root of the application in the container's file system

Save an image. I had created and started a container using VS 2019 just by adding docker support (right click on web project in solution explorer, Add/Docker support). It showed up in >docker ps and in >docker images. You can also use >docker container ls -a and you don't necessarily need the image id, you can use the ps and use the human readable value under the IMAGE column.
>docker save -o C:\Dev\Learning\Docker\CoreWebHelloWorld\image.tar 291a865d3b8a
     you have to use the image id, not container id, so go to >docker images to get the image id.


>docker load -i C:\Dev\Learning\Docker\CoreWebHelloWorld\image2.tar

Remove container.
>docker container rm [container id]

No comments:

Post a Comment