In this blog we will be doing following:
-Customize container name
user@mytest:~$ docker create -it –name=”my_container” ubuntu:latest /bin/bash
a8eccaa97e322ff640bb9f7071f191dc9a514afb324af28269ffbb7ae754677f
user@mytest:~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a8eccaa97e32 ubuntu:14.04 “/bin/bash” 4 seconds ago my_container
user@mytest:~$ docker start my_container
my_container
user@mytest:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a8eccaa97e32 ubuntu:14.04 “/bin/bash” 30 seconds ago Up 2 seconds my_container
user@mytest:~$ docker attach my_container
root@a8eccaa97e31:/#
root@a8eccaa97e31:/# exit
-Attach volume to docker
[user@mytest ~]$ mkdir docker
[user@mytest ~]$ cd docker
[user@mytest ~]$ mkdir mydata
[user@mytest ~]$ cd mydata
[user@mytest mydata]$ ll
total 0
[user@mytest mydata]$ echo “this is my host” >> mydata.txt
[user@mytest mydata]$ ll
total 4
-rw-rw-r– 1 user user 18 Aug 25 15:21 mydata.txt
[user@mytest mydata]$ cd ..
[user@mytest docker]$ ll
total 0
drwxrwxr-x 2 user user 23 Aug 25 15:21 mydata
[user@mytest docker]$ docker run -it –name=”rem_vol” -v /home/user/docker/mydata:/mydata centos:6 /bin/bash
[root@0476d5af242e /]# ls -al /mydata/
total 8
drwxrwxr-x 2 1000 1000 23 Aug 25 20:21 .
drwxr-xr-x 23 root root 4096 Aug 25 20:51 ..
-rw-rw-r– 1 1000 1000 18 Aug 25 20:21 mydata.txt
[root@0476d5af242e /]# cat /mydata/mydata.txt
this is my host