1 Pull an image centos7 from docker hub : https://hub.docker.com/_/centos/
docker pull centos
docker run --privileged -d -ti -v /sys/fs/cgroup:/sys/fs/cgroup:ro --name centos7100_7200 -p 7100-7200:7100-7200 -p 8100:80 -p 2020:22 centos /usr/sbin/init
Comman Details:
-
centos: is the name of image that was pulled to local host
-
centos7100_7200 : is the unique container name we set when create new container
-
-p 7100-7200:7100-7200 : expose range ports 7100-7200 from container to host machine with ranges 7100-7200
-
-p 8100:80 : expose port 80 on container to host machine 8100
-
-p 2020:22 : expose port 22 on container to host machine 2020
-
--privileged -d -ti -v /sys/fs/cgroup:/sys/fs/cgroup:ro this options help us run comman systemctl successfully on container
-
command to lunch a new container and share data from host machine with guest machine
docker run --privileged -d -ti -v /sys/fs/cgroup:/sys/fs/cgroup:ro -v f:/www:/www --name newcentos72 -p 22:22 -p 80:80 -p 8000-8100:8000-8100 -p 9000:9000 -p 9001:9001 -p 3306:3306 centos:latest /usr/sbin/init
docker run --privileged -d -ti -v /sys/fs/cgroup:/sys/fs/cgroup:ro -v e:/www:/www --name centos74php56 -p 22:22 -p 80:80 -p 443:443 -p 8000-8100:8000-8100 -p 9000:9000 -p 9001:9001 -p 3306:3306 -p 3389:3389 centos7new:newPhp7 /usr/sbin/init
-v e:/www:/www is folder from windows machine
docker exec -ti [container_id] /usr/bin/bash
this will help us login container centos7 via ssh.
yum update
yum install httpd
systemctl start httpd
now run browser on localhost : http://localhost-ip:8100 we see the welcome page of apache2
- on container comman change root password
passwd root
- on host run command
ssh root@localhost-ip -p 2020
Enter your password, then we will login to centos7 container.
docker export centos7new > centos7new-copy.tar
centos7new : name of current container
docker import centos7new-copy.tar centos7new:newPhp7
centos7new:newPhp7 : [IMAGENAME] : [NEWTAGE]