Professional Documents
Culture Documents
Docker Commands
Docker Commands
root@96e66e449eba:/usr/local/tomcat# ls
root@96e66e449eba:/usr/local/tomcat# cd webapps/
root@96e66e449eba:/usr/local/tomcat/webapps# ls
ROOT ROOT.war
root@96e66e449eba:/usr/local/tomcat/webapps#
https://github.com/docker-library/tomcat/issues/184
2. When we are running from Docker image from eclipse which uses tomcat 8 we need to
follow the below steps :
We need to start /run the container , and then run the exec command for the corresponding
container and move the dist file to webapp directory.
D:\DockerExamples\Tomcat\original\Chapter 7\fleetman-webapp>
3. But the problem with this container is that for each and every container we have to
manually exec the command and make it run. Hence in the docker file itself we can execute
the run command after the opentomcat image , to move the directory , this would ensure
that whenever I create new container with this latest image , it should work.
FROM tomcat:8.5.53-jdk8-openjdk
4. Also as a best practise whenever we run the image , we should remove the tomcat home
page from the docker , we shouldn’t be shipping this image in our container , hence we
would remove the ROOT directory present inside the webapp folder.
fc09c68f189f86733b5badb7b5eb8cec53d4d7684b893e112ab428ea2557409b
[
{
"Id": "42702d8f3eebcb82d004e2ca2b63ed1e090ab3c8a95164a3f7e41de7b82163fb",
"Created": "2020-04-10T08:51:31.291312348Z",
"Path": "docker-entrypoint.sh",
"Args": [
"mysqld"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 2862,
"ExitCode": 0,
"Error": "",
"StartedAt": "2020-04-11T08:28:46.02804104Z",
"FinishedAt": "2020-04-10T09:31:32.643305308Z"
},
"Image":
"sha256:413be204e9c34f31476a0680b6521873fb519c749693b181228ff47492a7fe3b",
"ResolvConfPath":
"/mnt/sda1/var/lib/docker/containers/42702d8f3eebcb82d004e2ca2b63ed1e090ab3c8a9516
4a3f7e41de7b82163fb/resolv.conf",
"HostnamePath":
"/mnt/sda1/var/lib/docker/containers/42702d8f3eebcb82d004e2ca2b63ed1e090ab3c8a9516
4a3f7e41de7b82163fb/hostname",
"HostsPath":
"/mnt/sda1/var/lib/docker/containers/42702d8f3eebcb82d004e2ca2b63ed1e090ab3c8a9516
4a3f7e41de7b82163fb/hosts",
"LogPath":
"/mnt/sda1/var/lib/docker/containers/42702d8f3eebcb82d004e2ca2b63ed1e090ab3c8a9516
4a3f7e41de7b82163fb/
42702d8f3eebcb82d004e2ca2b63ed1e090ab3c8a95164a3f7e41de7b82163fb-json.log",
"Name": "/vickidb",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "my-network",
"PortBindings": {},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Capabilities": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "private",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
30,
128
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": [],
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": null,
"DeviceRequests": null,
"KernelMemory": 0,
"KernelMemoryTCP": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": null,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"MaskedPaths": [
"/proc/asound",
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir":
"/mnt/sda1/var/lib/docker/overlay2/245d752f88dc6311f183da0730af092c92331fb984625af5
9b136a5f9a7b6dd0-init/diff:/mnt/sda1/var/lib/docker/overlay2/
dbd760ae70bc514acc0758f8574147041cc426a3de1a6e339b3e41434702f365/diff:/mnt/
sda1/var/lib/docker/
overlay2/5ccb174be64df15acd8d0c8223208b0dd07d225e3c44496ad9cb3e8b47cf1b18/
diff:/mnt/sda1/var/lib/docker/overlay2/
a9a5a4aa82f190a71188c55e9abfadf5331327578da3b21fc7e267ba80913c04/diff:/mnt/sda1/
var/lib/docker/overlay2/
a5e613df728c66a1dd4c47832a4250d59d3d88262c170fdf5aef830103abd042/diff:/mnt/
sda1/var/lib/docker/
overlay2/672bc715f15760b2f955fee45a421e68541f0d5eeaa1679440bae41206a81860/
diff:/mnt/sda1/var/lib/docker/overlay2/
e61e4fa9838b03b80d61469c235b49b366a465199744ff1fbcbf02caa40d7c99/diff:/mnt/sda1/
var/lib/docker/
overlay2/1d5dfd9e438bf0d28a5e944e59a64a3621f7a985e0b390903495789f3b29a92b/
diff:/mnt/sda1/var/lib/docker/
overlay2/27e382b96fefa22308475f34617909a2094c7b904e85854677be541ef5487a1b/
diff:/mnt/sda1/var/lib/docker/overlay2/
acfcbb7ca050043244a6bc67d9c1e0344adb5fc19bc898a3d88023cbd25b7383/diff:/mnt/
sda1/var/lib/docker/
overlay2/755732eba5eb68b791f479e040cb3e51485a0dca7066e151f2e6f6f2da955fa2/diff:/
mnt/sda1/var/lib/docker/
overlay2/2cccc122e703a09a356e1e9465e70e48ce3d90cb6c8bb7282cb13d2f4735c47e/diff",
"MergedDir":
"/mnt/sda1/var/lib/docker/overlay2/245d752f88dc6311f183da0730af092c92331fb984625af5
9b136a5f9a7b6dd0/merged",
"UpperDir":
"/mnt/sda1/var/lib/docker/overlay2/245d752f88dc6311f183da0730af092c92331fb984625af5
9b136a5f9a7b6dd0/diff",
"WorkDir":
"/mnt/sda1/var/lib/docker/overlay2/245d752f88dc6311f183da0730af092c92331fb984625af5
9b136a5f9a7b6dd0/work"
},
"Name": "overlay2"
},
"Mounts": [
{
"Type": "volume",
"Name":
"b9843a44e3bec9e733ff5680b7a014305367f6eb23960c623e9bffd6214e2e82",
"Source":
"/mnt/sda1/var/lib/docker/volumes/b9843a44e3bec9e733ff5680b7a014305367f6eb23960c6
23e9bffd6214e2e82/_data",
"Destination": "/var/lib/mysql",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
}
],
"Config": {
"Hostname": "42702d8f3eeb",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"3306/tcp": {},
"33060/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"MYSQL_ROOT_PASSWORD=password",
"MYSQL_DATABASE=fleetman",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"GOSU_VERSION=1.7",
"MYSQL_MAJOR=5.7",
"MYSQL_VERSION=5.7.29-1debian10"
],
"Cmd": [
"mysqld"
],
"Image": "mysql:5",
"Volumes": {
"/var/lib/mysql": {}
},
"WorkingDir": "",
"Entrypoint": [
"docker-entrypoint.sh"
],
"OnBuild": null,
"Labels": {}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID":
"2bec85e1f7bbae124d57b15f5a0792be673bc2d0d6aa676634780558a909eaa5",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"3306/tcp": null,
"33060/tcp": null
},
"SandboxKey": "/var/run/docker/netns/2bec85e1f7bb",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"my-network": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"42702d8f3eeb"
],
"NetworkID":
"2ee3ea655c920bd53f76b24fe01312785c7516e335c3091a574f3b51ec928d0f",
"EndpointID":
"39c2202b89222ad752f71796dc44cbc4b08d5872f46c5d8119517983fac7dd8c",
"Gateway": "172.18.0.1",
"IPAddress": "172.18.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:12:00:02",
"DriverOpts": null
}
}
}
}
]
15. To start the containers with docker compose , use the following command :
Docker-compose up
16. To run the application from maven using docker , we can make use of docker maven plugin
called io.fabric8
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.21.0</version>
<configuration>
<!--
<dockerHost>http://127.0.0.1:2375</dockerHost> -->
<!-- this is for Mac and Amazon Linux
-->
<!--
<dockerHost>unix:///var/run/docker.sock</dockerHost> -->
<verbose>true</verbose>
<images>
<image>
<name>vigneshramanujam/fleetman-webapp</name>
<build>
<dockerFileDir>$
{project.basedir}/src/main/docker/</dockerFileDir>
<!--copies Jar to
the maven directory (uses Assembly system) -->
<assembly>
<descriptorRef>artifact</descriptorRef>
</assembly>
<tags>
<tag>latest</tag>
</tags>
</build>
</image>
</images>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
17. To run the docker compose in the background use the following command
docker-compose up -d
18. To check for all the logs in the docker compose use the following commands
docker-compose logs -f
19. To check the logs for the given service , we have to use the following commands:
D:\DockerExamples\Tomcat\original\Chapter 7\fleetman-webapp>docker-
compose logs fleetman-webapp -f
ERROR: No such service: -f
D:\DockerExamples\Tomcat\original\Chapter 7\fleetman-webapp>docker-
compose logs -f fleetman-webapp
Attaching to fleetman-webapp_fleetman-webapp_1
D:\DockerExamples\Tomcat\original\Chapter 7\fleetman-webapp>docker-
compose down
Stopping fleetman-webapp_fleetman-webapp_1 ... done
Stopping fleetman-webapp_vickidb_1 ... done
Removing fleetman-webapp_fleetman-webapp_1 ... done
Removing fleetman-webapp_vickidb_1 ... done
Removing network fleetman-webapp_my-network
To create docker swarm , or to create an initial node , we need to give the command
We would get an error we need to associate this with some ip , to get it done.
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the
instructions.
22. To create a service inside docker swarm
D:\DockerExamples\Tomcat\original\Chapter 7\fleetman-webapp>docker
network create --driver overlay fleetman-network
zjiab5pwnzee9b1stnnri1epy
D:\DockerExamples\Tomcat\original\Chapter 7\fleetman-webapp>docker
network ls
NETWORK ID NAME DRIVER SCOPE
fdf56f9d029d bridge bridge local
f0c16461375d docker_gwbridge bridge local
zjiab5pwnzee fleetman-network overlay swarm
342fc94414b6 fleetman-webapp_my-network bridge local
d73ec77f8ced host host local
x0y37qumv7kr ingress overlay swarm
667ad0abc2eb my-network bridge local
d15ca4a06773 none null local
D:\DockerExamples\Tomcat\original\Chapter 7\fleetman-webapp>docker
container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS
PORTS NAMES
38440cf17496 mysql:5 "docker-entrypoint.s…" 4 seconds ago Up 5 seconds
3306/tcp, 33060/tcp database.1.l7etsvnajtjz985q8f68joxac
$ docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
ENGINE VERSION
rnnp99urn3e2vffc7wufyawjz * node1 Ready Active Leader
19.03.4
icv3ff1bqw7gzmn8loptltk3n node2 Ready Active
19.03.4
Docker node ls will only work in the master node /manager node , it will not work on the
servant/slaves node
nai6h4agjib8sc5aeh5ejq8o2