Stateless : Store the data externally, design the container running with external data. Therefore, data will be stored if container deletes.
- docker run -d
Lets create mysql:5.7 container. And then let my host directory to share with container(mysql:5.7 ) directory.
docker run -d --name wordpressdb_hostvolume -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=wordpress -v /Users/joohyunyoon/wordpress_db:/var/lib/mysql mysql:5.7
fa11c38fc73e12370c6363b37bded225b78bd901adf180ddcce03051d6e78b1a
-d : Detached, opposite to -i -t in other words, it estabilished running the application on the foreground, unlike interactive mode -i -t. It executes the container without input and output. It doesnt receive user's input
-e : Environment, establish inner environment variable
-v or --volume : Volume, share the each containers, seperated by colon characters(:).
/Users/joohyunyoon/wordpress_db:/var/lib/mysql
host:container
-->sharing host directory and container directory
And then let two containers link together(wordpress, mysql).
Create wordpress container which name is wordpress_hostvolume.
The 80 port is exposed, it can be accessible with host port.
docker run -d -e WORDPRESS_DB_PASSWORD=password --name wordpress_hostvolume --link wordpressdb_hostvolume:mysql -p 80 wordpress
2751e54411bde98cc979569a0bad77cb3be875c56695b182fba9b101fcd2dcf4
ls /Users/joohyunyoon/wordpress_db/
auto.cnf client-key.pem ibdata1 private_key.pem sys
ca-key.pem ib_buffer_pool ibtmp1 public_key.pem wordpress
ca.pem ib_logfile0 mysql server-cert.pem
client-cert.pem ib_logfile1 performance_schema server-key.pem
There are all sorts of mysql files shared in /Users/joohyunyoon/wordpress_db
After remove all of them, let's check them out whether they are still there or not.
docker stop wordpress_hostvolume wordpressdb_hostvolume
wordpress_hostvolume
wordpressdb_hostvolume
docker rm wordpress_hostvolume wordpressdb_hostvolume
wordpress_hostvolume
wordpressdb_hostvolume
ls /Users/joohyunyoon/wordpress_db/
auto.cnf client-key.pem ibdata1 public_key.pem wordpress
ca-key.pem ib_buffer_pool mysql server-cert.pem
ca.pem ib_logfile0 performance_schema server-key.pem
client-cert.pem ib_logfile1 private_key.pem sys
//there are still here alive!
- docker volume create --name myvolume
Create volume which name is myvolume.
docker volume create --name myvolume
myvolume
docker volume ls
DRIVER VOLUME NAME
local myvolume
docker run -i -t --name myvolume_1 -v myvolume:/Users/joohyunyoon/ ubuntu:14.04 //myvolume has been mounted to Users/joohyunyoon/
root@1973b8bfb876:/# echo hello
hello
docker volume ls : check the volume list
- docker inspect --type volume myvolume
docker inspect --type volume myvolume
[
{
"CreatedAt": "2021-02-17T09:06:49Z",
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/myvolume/_data",
"Name": "myvolume",
"Options": {},
"Scope": "local"
}
]
inspect : return low-level informatino on docker objects
--type : return JSON for specified type
- docker system prune --volumes
To remove all unused volumes.
'Docker' 카테고리의 다른 글
Install the docker-compose (0) | 2021.04.12 |
---|---|
MAC address, VLAN, LAN, -d, --driver, --subnet, --ip-range, -o, (0) | 2021.02.23 |
--net, HWaddr, --net-alias, grep, -c, round-robbin, dig (0) | 2021.02.22 |
network, bridge, host, none (0) | 2021.02.22 |
docker, linuxkit, virtualbox, instance, volume, snapshots, EC2, tty (0) | 2021.02.09 |