How To Create Docker Image And Run Container
Posted By : Chandan Kumar Singh | 28-Feb-2018
Docker is a tool which is used for creating, deploy and run the application by using containers. The container is nothing but the package which consists all the libraries and dependencies required for running the application. By doing this, the developer can be assured that the application will run on any Linux system without any customized setting.
Let's start doing some stuff on Docker. We will install docker on Ubuntu, will create ubuntu image with Java-8 installed.
Install Docker CE on Ubuntu 14.04 LTS
apt-get update apt-get install linux-image-extra- uname linux-image-extra-virtual
Update the package index.
Install package to allow package from https
apt-get install apt-transport-https ca-certificates curl software-properties-common
Add Docker's GPG key.
curlhttps://download.docker.com/linux/ubuntu/gpg | apt-key add -
setup stable repositry
update the package index
Install docker CE
apt-get install docker-ce
Installation is done.
Now run the ubuntu image in docker by
Install Java in Image
apt-get update apt-get install software-properties-common add-apt-repository ppa:webupd8team/java apt-get install oracle-java8-installer
commit the changes
docker commit -a "authoername" -m "messg" CID(container id)
Now save the commited image
docker image save -o ubuntu-java8 ubuntu
here ubuntu is the image name which will be saved on disk by the name of ubuntu-java8.
To list the available docker image, run
to list the available docker containers, run
docker container ls -a
to run the docker image, run
docker run -itd --name "myname" 21c6c6c37ece(image id) /bin/bash
to run the image container
docker exec -it 2c536d59d66b(container id) /bin/bash