As a learning curve, I had marked Docker in my list
So just tipping some quick commands for your and my own reference as it is not a primary tool I am using day-to-day
Display Docker Images:
$ docker images
Run Docker Image:
$ docker run hello-world
Note: If you do not have an image in your local machine, docker will look into docker hub (over the internet)
Write a docker file:
$ mkdir dockerfolder
$ cd dockerfolder
$ vim newdockerfile
RUN apt-get -y update && apt-get install -y telnet
save and close your newdockerfile “wq!”
Build and image from our Docker File
$ docker build -t telnet-install .
Note: we are using a period in the end of docker build command to represent the newdockerfile within the directory
If you want to run new build file: “docker run telnet-install”
Tag your image-id: (required if you want to push to docker hub)
$ docker tag 693bce725149 terminaltolinux/telnet-install:latest
Note: image id can be found from “docker images” command
Login to docker hub:
$ docker login –username=terminaltolinux –email=terminal@linux.com
Note: after docker login command it will prompt for password, prior have a docker hub account
Push docker image to docker hub account:
$ docker push terminaltolinux/telnet-install
Note: Verify from docker hub account, the docker image will be pushed. Prior create a repo on docker hub
Delete a docker image:
$ docker rmi -f terminaltolinux/telnet-install
Pull docker image from docker hub account:
$ docker run terminaltolinux/telnet-install
Note: it will not find in the local machine as we deleted earlier and will fetch it online and run it, however “docker pull terminaltolinux/telnet-install” can also be used to just pull the image.
Search docker image:
$ docker search mysql
Search docker image with number of stars:
$ docker search -s 1 mysql
Run docker image in background:
$ docker run -d mysql
Run docker image with interactive session:
$ docker run -it ubuntu
List running containers
$ dockers ps
Inspect a container
$ docker inspect <container-id>
Note: container-id will be available from “docker ps”
Logs of standard error or standard out
$ docker log <container-id>
Commit changes to container and save as a separate image. (tag it):
$ docker commit <container-id> nginx-ubuntu
Port binding to container
$ docker run -d -p 6379 reds
Note: -p binds port but if we wanted to map this port directly on the host, we will use the option -p 6379:6379 and if with particular ip then -p 127.0.0.1:6379:6379
Binding directories
$ docker run -d -v “/home/docker/data”:/data reds
Start a container
$ docker start <container-id>
Stop a container
$ docker stop <container-id>
Remove an exited container
$ docker rm <container-id>
Restart a container
$ docker restart <container-id>
Use docker with proxy:
If you want to run docker with environment proxy, edit /etc/default/docker amend your entry for http_proxy
TIP:
If we don’t tell docker explicitly we want to map port, it will block access through that port (because containers are isolated until you tell them you want access)