Difference between revisions of "Docker"
From Teknologisk videncenter
m |
m |
||
(18 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | + | {|border=1 ;style="margin: 0 auto; text-align: center;cellpadding="5" cellspacing="0"; | |
|- bgcolor=lightgrey | |- bgcolor=lightgrey | ||
! command !! Explanation | ! command !! Explanation | ||
Line 9: | Line 9: | ||
|docker container ls||Status of running containers (As above) | |docker container ls||Status of running containers (As above) | ||
|- | |- | ||
− | |docker run ubuntu|| Run | + | |docker run ubuntu|| Run image ubuntu in containe (Terminates as its bash exits) - pull container if not present |
|- | |- | ||
− | |docker run -it ubuntu|| Run container | + | |docker run -d nginx || Run image nginx detach (as daemon stdin/stdout detached) |
+ | |- | ||
+ | |docker run -d -p 8080:80 nginx || Run image nginx detach (portmap redirect 8080->80) public to private - See rule with '''iptables -L -t nat -n''' or '''nft list ruleset''' | ||
+ | |- | ||
+ | |docker run -d -p 8080:80 -v /home/heth/nginx:/usr/share/nginx/html nginx || Same as above but with volume map. Actually mounts directory in container | ||
+ | |- | ||
+ | |docker run -it ubuntu|| Run image ubuntu in container ( -it = interactive tty ) | ||
+ | |- | ||
+ | |docker pull nginx || pull container from repository (default docker hub) | ||
+ | |- | ||
+ | |docker inspect 1e5bdae517e7 || JSON dump of container config | ||
+ | |- | ||
+ | |docker container prune || Remove all stopped containers | ||
+ | |- | ||
+ | |docker exec -ti 1e5bdae517e7 bash || Run interactive bash in running container | ||
+ | |- | ||
+ | |docker attach 1e || attach your terminal's standard input, output, and error to a running container | ||
|- | |- | ||
|} | |} | ||
+ | == Container preservation == | ||
+ | <source lang=bash> | ||
+ | root@ub1:~# docker run -it --name heth alpine | ||
+ | / # echo "Hello, alpine" > hethfile.txt | ||
+ | / #<CTRL-D> | ||
+ | root@ub1:~# docker start -ai heth | ||
+ | / # cat hethfile.txt | ||
+ | Hello, alpine | ||
+ | / #<CTRL-D> | ||
+ | root@ub1:~# docker rm heth | ||
+ | </source> | ||
+ | ==Running command in container== | ||
+ | <source lang=bash> | ||
+ | # echo "print("Hello, world")" > /tmp/hello.py | ||
+ | # docker run -it -v /tmp:/app python python3 /app/hello.py | ||
+ | Hello,world | ||
+ | </source> | ||
+ | =Docker engine= | ||
+ | ==Directories== | ||
+ | ;/var/lib/docker | ||
+ | : Base directory | ||
+ | |||
Latest revision as of 09:04, 29 September 2024
command | Explanation |
---|---|
docker ps | Status of running containers |
docker container ls | Status of running containers (As above) |
docker run ubuntu | Run image ubuntu in containe (Terminates as its bash exits) - pull container if not present |
docker run -d nginx | Run image nginx detach (as daemon stdin/stdout detached) |
docker run -d -p 8080:80 nginx | Run image nginx detach (portmap redirect 8080->80) public to private - See rule with iptables -L -t nat -n or nft list ruleset |
docker run -d -p 8080:80 -v /home/heth/nginx:/usr/share/nginx/html nginx | Same as above but with volume map. Actually mounts directory in container |
docker run -it ubuntu | Run image ubuntu in container ( -it = interactive tty ) |
docker pull nginx | pull container from repository (default docker hub) |
docker inspect 1e5bdae517e7 | JSON dump of container config |
docker container prune | Remove all stopped containers |
docker exec -ti 1e5bdae517e7 bash | Run interactive bash in running container |
docker attach 1e | attach your terminal's standard input, output, and error to a running container |
Container preservation
root@ub1:~# docker run -it --name heth alpine
/ # echo "Hello, alpine" > hethfile.txt
/ #<CTRL-D>
root@ub1:~# docker start -ai heth
/ # cat hethfile.txt
Hello, alpine
/ #<CTRL-D>
root@ub1:~# docker rm heth
Running command in container
# echo "print("Hello, world")" > /tmp/hello.py
# docker run -it -v /tmp:/app python python3 /app/hello.py
Hello,world
Docker engine
Directories
- /var/lib/docker
- Base directory