How to create a new docker image
Steps to create, test and push a docker image
- Download and install Docker Desktop. If on Linux, download Docker Engine - Community.
- Create a Docker file with the name Dockerfile or download one.
-
Simple docker file example
FROM ubuntu:18.04 RUN apt-get update RUN apt install -y python3 RUN python3 --version
-
>notepad Dockerfile
-
Login to docker hub
>docker login
-
Make changes to docker file and build it
>docker build --rm -t krishan_apex:latest . Sending build context to Docker daemon 3.584kB **** installs a bunch of packages *** **** installs some more packages *** Successfully built 4a4cc017fe68
-
See the list of docker images
> docker images REPOSITORY TAG IMAGE ID CREATED SIZE krishan_apex latest 4a4cc017fe68 2 minutes ago 6.33GB
-
Create a repository in docker hub
-
Tag your image with <username>/<reponame>:<tag>
> docker tag krishan_apex krishansubudhi/pytorch_apex:latest
-
Run the container on your machine using the image you just created.
> docker run -it -d -p 5000:5000 krishansubudhi/pytorch_apex:latest
-
Check all running docker containers
> docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 55c7cfc80e35 krishansubudhi/pytorch_apex:latest "/bin/bash" 15 seconds ago Up 13 seconds 5001/tcp, 8883/tcp, 0.0.0.0:5000->5000/tcp, 8888/tcp angry_elbakyan
-
Log in to terminal of runing container and run simple linux commands.
docker attach 55c7cfc80e35
-
Push the image to dockerhub repo to be accessed by everyone. This takes a long time.
docker push krishansubudhi/pytorch_apex:latest
Reference :
IBM tutorial Official documentation What is Docker. RUN vs CMD vs ENTRYPOINT