Docker: Difference between revisions

3,466 bytes added ,  2 years ago
(→‎RancherOS: added)
 
(16 intermediate revisions by the same user not shown)
Line 2:
__TOC__
<br />
 
= Basics =
*Docker Components:
 
- Image: Content at rest, Not the full OS, but just the basic environment
- Container: Running Image
- Engine: Software that executes commands for containers. Networking & Volumes are part of Engine.
- Registry: Stores, Distributes & Manages docker images.
- Control Plane: Management Plane for Container & Cluster Orchestration.
 
*Container Orchestration:
- Docker Swarm
- [[Kubernetes]]
- Mesos Marathon
- Cloud Foundry Diego
- Amazon ECS
- Azure Container Service
 
= Installation =
Line 41 ⟶ 58:
Removing a Container:
docker rm <container-id>
 
Delete all containers:
docker rm $(docker ps -a -q)
 
Delete all images:
docker rmi $(docker images -q)
 
Force delete all images (even with linked containers):
docker rmi $(docker images -q) --force
 
Remove all stopped containers, unused volumes, unused networks, all images without at least one container associated to them:
docker system prune -a -f
 
= Installing MediaWiki =
Line 51 ⟶ 80:
 
;Databases Credentials
 
Default Mysql credentials are:
admin
pass
 
Use the following command to update or reset MariaDB user password. The below command will set a new admin user password:
Line 58 ⟶ 91:
docker exec -it mediawiki mysqladmin -uadmin -ppass create mediawiki2
 
Use the below command to copy the LocalSetting.php file from host to Docker:
= NGINX =
docker cp LocalSettings.php mediawiki:/var/www/html/LocalSettings.php
 
= NGINXNginx =
Source: [https://www.digitalocean.com/community/tutorials/how-to-run-nginx-in-a-docker-container-on-ubuntu-14-04 digitalocean.com]
 
Line 87 ⟶ 123:
docker search nginx
 
Run nginx docker image with auto Restart on reboot option
docker run --name nginx -p 80:80 -d -v ~/docker-/nginx/html:/usr/share/nginx/html --restart unless-stopped nginx
 
Docker currently has four restart policies[https://blog.codeship.com/ensuring-containers-are-always-running-with-dockers-restart-policy/]:
no
on-failure
unless-stopped
always
 
;Multiple Instances
Create copies of root directory for different servers:
cp -r ~/docker-/nginx/ ~/docker-/nginx8080/
cp -r ~/docker-/nginx/ ~/docker-/nginx8081/
cp -r ~/docker-/nginx/ ~/docker-/nginx8082/
cp -r ~/docker-/nginx/ ~/docker-/nginx8083/
 
Edit the Index.html file to reflect different content by editing the html code.
 
Start different instances of nginx to start with different ports & root directories:
docker run --name nginx8080nginx8081 -p 80808081:80 -d -v ~/docker-nginx8080/nginx8081/html:/usr/share/nginx/html nginx
docker run --name nginx8081nginx8082 -p 80818082:80 -d -v ~/docker-nginx8081/nginx8082/html:/usr/share/nginx/html nginx
docker run --name nginx8082nginx8083 -p 80828083:80 -d -v ~/docker-nginx8082/nginx8083/html:/usr/share/nginx/html nginx
docker run --name nginx8083nginx8084 -p 80838084:80 -d -v ~/docker-nginx8083/nginx8084/html:/usr/share/nginx/html nginx
 
Nginx instances should now be available using below links:
http://<IP_of_Server>:8080
http://<IP_of_Server>:8081
http://<IP_of_Server>:8082
http://<IP_of_Server>:8083
http://<IP_of_Server>:80808084
 
;Changing port or running custom config:
Copy the nginx file from docker file system to local filesystem:
sudo docker cp nginx:/etc/nginx/conf.d/default.conf /home/aman/docker/default.conf
 
Edit the config file to change the listening port to 8000:
nano default.conf
 
Now start the docker container with the new port:
docker run --name docker-nginx -p 8081:8000 -v ~/docker/nginx8081/html:/usr/share/nginx/html -v ~/docker/default.conf:/etc/nginx/conf.d/default.conf -d nginx
 
;Running multiple instances with custom ports & autostart on bootup:
<pre style="width: 97%; overflow-x: scroll;">
docker run --name nginx8081 -p 8081:8000 -d -v ~/docker/nginx8081/html:/usr/share/nginx/html -v ~/docker/default.conf:/etc/nginx/conf.d/default.conf --restart unless-stopped nginx
docker run --name nginx8082 -p 8082:8000 -d -v ~/docker/nginx8082/html:/usr/share/nginx/html -v ~/docker/default.conf:/etc/nginx/conf.d/default.conf --restart unless-stopped nginx
docker run --name nginx8083 -p 8083:8000 -d -v ~/docker/nginx8083/html:/usr/share/nginx/html -v ~/docker/default.conf:/etc/nginx/conf.d/default.conf --restart unless-stopped nginx
docker run --name nginx8084 -p 8084:8000 -d -v ~/docker/nginx8084/html:/usr/share/nginx/html -v ~/docker/default.conf:/etc/nginx/conf.d/default.conf --restart unless-stopped nginx</pre>
 
=Ntop=
Downloading and installing image first time
docker pull lucaderi/ntopng-docker
docker run --net=host --name ntopng -t -i lucaderi/ntopng-docker ntopng -v
 
Let it run for few minutes.<br/>
Now press Control+C keys to terminate the process.<br/>
Now to start it type the below command:
docker start ntopng
<br/>
 
= RancherOS =
Line 121 ⟶ 191:
sudo ifconfig eth0 inet 10.10.10.10 netmask 255.255.255.0 broadcast 10.10.10.255
sudo route add default gw 10.10.10.1
 
sudo vi /etc/resolv.conf
nameserver 10.10.10.5
 
Check Internet connectivity
Line 128 ⟶ 201:
sudo ros install -d /dev/xvda
 
Set the persistent networking:
sudo vi /etc/networking/interfaces
 
Install Linux-dash, a minimal low-overhead web dashboard for monitoring Linux servers
sudo system-docker run -d --net=host --name busydash husseingalal/busydash
 
WebUI Access:
http://<IP_OF_MACHINE>
 
Default password is blank for user 'rancher'. Change it for SSH login:
passwd
 
SSH Login:
{{UC}}
ssh-keygen
 
= Docker Packet Captures =
docker exec -it 428947239426349 tcpdump -N -A 'port 80' -w capture.pcap
 
<br />