Docker Administrator I | How Manage Docker
Environment
Create VM using Vagrant, create file Vagrantfile
Vagrant.configure("2") do |config|
config.vm.define "node1" do |node1|
node1.vm.box = "centos/7"
node1.vm.hostname = "vm1.roomit.tech"
node1.vm.network "private_network", ip: "192.168.33.11"
node1.vm.provider "virtualbox" do |vb|
vb.name = "node1"
vb.memory = "1024"
end
endconfig.vm.define "node2" do |node2|
node2.vm.box = "centos/7"
node2.vm.hostname = "vm2.roomit.tech"
node2.vm.network "private_network", ip: "192.168.33.12"
node2.vm.provider "virtualbox" do |vb|
vb.name = "node2"
vb.memory = "1024"
end
end
end
Running Vagrant
vagrant up
Enter to VM1 and VM2
vagrant ssh vm1
and
vagrant ssh vm2
in Both Server and Install
sudo su
# apt update
# apt -y install docker.io
# systemctl status docker
# systemctl start docker
Management Images
- View Docker Version
sudo docker version
2. Check Docker info
sudo docker info
3. Testing Hello World On Docker
sudo docker run hello-world
4. Pull Image
sudo docker pull wajatmaka/dockerizing:flask
5. Lisitng Images
sudo docker image ls
6. Tags Image For Pushing
sudo docker image push wajatmaka/dockerizing:flask
7. Push Image
sudo docker image push wajatmaka/dockerizing:flask
8. Inspect Image
sudo docker image inspect [ID IMAGE]
9. Build Images
sudo docker image build .
10. Remove Image
sudo docker image rm [ID IMAGE]
Management Container
- Lisiting Container
sudo docker container ls -a
2. Stop Container
sudo docker container stop [ID CONTAINER]
3. Start Container
sudo docker container start [ID CONTAINER]
4. Restart Container
sudo docker container restart [ID CONTAINER]
5. Monitoring Container Realtime
sudo docker container stats [ID CONTAINER]
6. Copy File To Container
sudo docker container cp [NameOfFile] [ID CONTAINER]:/
7. Commit if changes in container, this is will create new image
sudo docker container commit [[ID CONTAINER] wajatmaka/dockerizing:flask2
8. Login To Container
sudo docker container exec -it [ID CONTAINER] bash
9. Show Container Logs
sudo docker container logs [ID CONTAINER]
10. Pause Process Container
sudo docker container pause [ID CONTAINER]
testing access with curl:
curl localhost:4000
output will be timeout.
11. Unpause Process Container
sudo docker container unpause [ID CONTAINER]
testing access with curl::
curl http://localhost:4000
output will be get code 200 success.
12. Kill Process Container
sudo docker container kill [ID CONTAINER]
13. Cleaning All Container when Container Stopped
sudo docker container prune
14. Inspect Information Container
sudo docker container inspect [ID CONTAINER]
Inspect Spesific, example how to get IP container:
sudo docker container inspect -f "\{\{ \.NetworkSettings.IPAddress \}\}" [ID CONTAINER]
15. Destroy Container
sudo docker container rm [ID CNTAINER]