Docker Volumes Contd..
- Generally for stateful application containers, its a good idea to create a VOLUME as part of Dockerfile.
- Experiment:
- Create a volume for mysql data and mount that into mysql container
- insert some data into it
- delete the container
- Create a new mysql container and reuse the same volume and verify if the data is present or not.
- To interact with mysql container Refer Here
- To create the container we have used
docker container run --name mysql-primary -d -P --mount "source=mysql-employee-vol,target=/var/lib/mysql" -e "MYSQL_ROOT_PASSWORD=rootroot" -e "MYSQL_USER=qtdevops" -e "MYSQL_PASSWORD=qtdevops" -e "MYSQL_DATABASE=employee" mysql - To login into mysql prompt
docker container exec -it mysql-primary mysql -u root -p - To create a table
use employee;
CREATE TABLE authors (id INT, name VARCHAR(20), email VARCHAR(20));
INSERT INTO authors (id,name,email) VALUES(1,"Vivek","xuz@abc.com");
INSERT INTO authors (id,name,email) VALUES(2,"Priya","p@gmail.com");
INSERT INTO authors (id,name,email) VALUES(3,"Tom","tom@yahoo.com");
select * from authors;
- Create a volume for mysql data and mount that into mysql container
- Tmpfs mount: This gets mounted to the RAM/memory into container. This is useful only for applications which require preset data to be present in memory
Networking
- Every container is getting an ip address
- Docker has a subcommand for network
- lets see what are the networks available
- Two possible Networing options identified
- Share the same network of docker host to the container
-
Create a new network on the docker host and make it available to the containers. Connect the network created by docker host to the network docker host is connected by using a bridge
-
Experiment:
- Created a linux vm and verified network interfaces. we had two interfaces
- loopback (lo) => 127.0.0.1/localhost
- eth0
- We had installed docker on the linux machine and one more interface got created
- docker0
- Now we have create a docker container and verified the network interfaces we got two interfaces
- loopback (lo)
- eth0
- Created a linux vm and verified network interfaces. we had two interfaces
