Docker Image is basically a snapshot of file system at specific time can be used to create containers
1. Docker Installation:
Install EPEL repositories to install docker
yum install epel-release
start docker service (service docker start)
verify docker installed properly as below
#docker version
#docker info
#ps faux
2. Creation of Docker Image:
Create a script (Docker file) to create an image.
We can get it from https://github.com/docker/docker/tree/master/contrib
modify yum repo based on version we are trying to create docker image
save the docker image using below command.
docker save <id> > /tmp/centos65base.tar
docker load < /root/centos65base.tar
3. Verification of image which we created
#docker images
#docker ps -all
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
<none> <none> ed49ce70a44d 21 minutes ago 272.4 MB
[root@localhost ~]# docker tag ed49ce70a44d centos7base:7
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos7base 7 ed49ce70a44d 21 minutes ago 272.4 MB
4. Start the container from docker image as below. we can start from same machine or from other machine
#docker run -i -t ed49ce70a44d /bin/bash
In case if you exit from docker container
we need to below to get into container to re-connect.
docker start <container id>
docker attach <Container id>
do not exit from container, instead use "ctrl +p and ctrl +q" to come to HOST system.
5. Commiting the changes that we made in container, when we commit new image gets created as below.
[root@localhost ~]# docker commit 6d1b4d04bd5a centos7base-commit
cea4e70c4bf833605ed06bb9fc60c722bf9870423633a93e5f0c030c7f7d4b8b
#docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos7base-commit latest cea4e70c4bf8 About a minute ago 272.9 MB
centos7base 7 ed49ce70a44d 54 minutes ago 272.4 MB
[root@HOST ~]# docker run --device=/dev/sdb --net='host' --privileged=true -it ed49ce70a44d /bin/bash
[root@container /]# fdisk -l
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
$ DOCKER_NVIDIA_DEVICES="--device /dev/nvidia0:/dev/nvidia0 --device /dev/nvidiactl:/dev/nvidiactl --device /dev/nvidia-uvm:/dev/nvidia-uvm"
$ sudo docker run -ti $DOCKER_NVIDIA_DEVICES tleyden5iwx/ubuntu-cuda /bin/bash
PRIVILIZED CONTAINER:
=====================
has access to all the devices, instead of being restricted to a small, sane set of devices;
retains all the capabilities of the host. It means that this container will be able to mknod, mount, etc.
1. Docker Installation:
Install EPEL repositories to install docker
yum install epel-release
start docker service (service docker start)
verify docker installed properly as below
#docker version
#docker info
#ps faux
2. Creation of Docker Image:
Create a script (Docker file) to create an image.
We can get it from https://github.com/docker/docker/tree/master/contrib
modify yum repo based on version we are trying to create docker image
save the docker image using below command.
docker save <id> > /tmp/centos65base.tar
docker load < /root/centos65base.tar
3. Verification of image which we created
#docker images
#docker ps -all
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
<none> <none> ed49ce70a44d 21 minutes ago 272.4 MB
[root@localhost ~]# docker tag ed49ce70a44d centos7base:7
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos7base 7 ed49ce70a44d 21 minutes ago 272.4 MB
4. Start the container from docker image as below. we can start from same machine or from other machine
#docker run -i -t ed49ce70a44d /bin/bash
In case if you exit from docker container
we need to below to get into container to re-connect.
docker start <container id>
docker attach <Container id>
do not exit from container, instead use "ctrl +p and ctrl +q" to come to HOST system.
5. Commiting the changes that we made in container, when we commit new image gets created as below.
[root@localhost ~]# docker commit 6d1b4d04bd5a centos7base-commit
cea4e70c4bf833605ed06bb9fc60c722bf9870423633a93e5f0c030c7f7d4b8b
#docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos7base-commit latest cea4e70c4bf8 About a minute ago 272.9 MB
centos7base 7 ed49ce70a44d 54 minutes ago 272.4 MB
[root@HOST ~]# docker run --device=/dev/sdb --net='host' --privileged=true -it ed49ce70a44d /bin/bash
[root@container /]# fdisk -l
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
$ DOCKER_NVIDIA_DEVICES="--device /dev/nvidia0:/dev/nvidia0 --device /dev/nvidiactl:/dev/nvidiactl --device /dev/nvidia-uvm:/dev/nvidia-uvm"
$ sudo docker run -ti $DOCKER_NVIDIA_DEVICES tleyden5iwx/ubuntu-cuda /bin/bash
PRIVILIZED CONTAINER:
=====================
has access to all the devices, instead of being restricted to a small, sane set of devices;
retains all the capabilities of the host. It means that this container will be able to mknod, mount, etc.
No comments:
Post a Comment