DCP Container Basics - degutos/wikis GitHub Wiki
How to display running container
[user@andregonzaga1 ~]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
How to display all container already ran once
[user@andregonzaga1 ~]$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
06cdf37f6a16 hello-world "/hello" 2 minutes ago Exited (0) 2 minutes ago wonderful_chan
drasekhar
fe92f29402e8 hello-world "/hello" 20 hours ago Exited (0) 20 hours ago inspiring_mont
alcini
How to create a container in an interactive way
[user@andregonzaga1 ~]$ docker run -it centos:6
How to create container in an interactive way and set the container name and set /bin/bash to run as process
[user@andregonzaga1 ~]$ docker run -it --name testcontainer centos:6 /bin/bash
How to Stop a container running
[user@andregonzaga1 ~]$ docker stop testcontainer
How to remove all container
[user@andregonzaga1 ~]$ docker rm `docker ps -a -q`
How to create a container and delete automatically after running it
[user@andregonzaga1 ~]$ docker run -it --rm --name testcontainer centos:6
How to create a container with VARIABLE
[user@andregonzaga1 ~]$ docker run -it --rm --env MYVAR=whatever --name testcontainer centos:6
[root@255701eed28c /]# echo $MYVAR
whatever
[user@andregonzaga1 ~]$ docker run -it --rm --env MYVAR=whatever --env MYVAR2=something --name testcontainer centos:6
[root@ec1db9bb60d0 /]# echo $MYVAR
whatever
[root@ec1db9bb60d0 /]# echo $MYVAR2
something
How to create a container in foreground state as a demon -d
[user@andregonzaga1 ~]$ docker run -d httpd
d53af8402fad2e905988ec8cb0206fe7dfceeee08b6f94155fcfb6b8cfe74f65
[user@andregonzaga1 ~]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d53af8402fad httpd "httpd-foreground" 3 seconds ago Up 2 seconds 80/tcp kind_jepsen
How to attach to a running container with kill it after exit
[user@andregonzaga1 ~]$ docker exec -ti kind_jepsen /bin/bash
OR
- To leave the container and leave it running
Control + p + q