Some of the useful docker commands

List Docker images in system
docker images 
sanjeewa@sanjeewa-ThinkPad-X1-Carbon-3rd:~/work/docker$ docker images 
REPOSITORY                                       TAG                 IMAGE ID            CREATED             SIZE
dockerhub.private.wso2.com/sanjeewa-testubuntu   latest              a71fcdc506aa        6 minutes ago       188 MB
sanjeewa-ubuntu                                  latest              a71fcdc506aa        6 minutes ago       188 MB
dockerhub.private.wso2.com/ubuntu                latest              b72889fa879c        11 weeks ago        188 MB

List running docker instances
docker ps
Get the differences between instances
docker diff 
Commit running instance after some changes to local repository
docker commit c951e2725fca9519c82d665fba4fc1439a8076a6ca1a266783e0578a7d76fb3f sanjeewa-ubuntu
Tag docker available in local repo.
docker tag sanjeewa-ubuntu dockerhub.private.wso2.com/sanjeewa-testubuntu

Export image to repo
>docker push dockerhub.private.wso2.com/sanjeewa-testubuntu
The push refers to a repository [dockerhub.private.wso2.com/sanjeewa-testubuntu]
863e132d4800: Pushed
5f70bf18a086: Pushed
f75f146a5022: Pushed
711b0bd2cb6a: Pushed
595d1d53a534: Pushed
latest: digest: sha256:5fbd869f1c9a169c8811b34dd30a7f5dfac4335ecb98e3f22c629c9e2bf4a83a size: 1358


Import image from file system
docker load < wso2am.tgz
docker images 
REPOSITORY                                       TAG                 IMAGE ID            CREATED             SIZE
dockerhub.private.wso2.com/sanjeewa-testubuntu   latest              a71fcdc506aa        18 minutes ago      188 MB
sanjeewa-ubuntu                                  latest              a71fcdc506aa        18 minutes ago      188 MB
dockerhub.private.wso2.com/wso2am                1.10.0              7ae5de86a076        3 weeks ago         1.032 GB
dockerhub.private.wso2.com/nginx                 latest              2fede7433e44        4 weeks ago         182.8 MB
dockerhub.private.wso2.com/svnrepo               latest              0530ac8e24b0        9 weeks ago         228.8 MB
dockerhub.private.wso2.com/ubuntu                latest              b72889fa879c        11 weeks ago        188 MB
dockerhub.private.wso2.com/mysql                 5.5                 783151ba5745        11 weeks ago        256.9 MB


Run docker instance
docker run -p 9443:9443 dockerhub.private.wso2.com/wso2am:1.10.0
Creating directory /mnt/172.17.0.2...

List running docker instances
docker ps
CONTAINER ID        IMAGE                                      COMMAND                  CREATED             STATUS              PORTS                                                             NAMES
9867acff0f65        dockerhub.private.wso2.com/wso2am:1.10.0   "/usr/local/bin/init."   2 minutes ago       Up 2 minutes        8243/tcp, 8280/tcp, 9763/tcp, 10397/tcp, 0.0.0.0:9443->9443/tcp   sad_kirch


Get logs from container
docker logs -f 9867acff0f65

Access remote machine terminal
docker exec -it 9867acff0f65 /bin/bash
root@9867acff0f65:/mnt# 

List all meta-data
docker inspect 3c78e0d8947a
To stop running instalce
docker stop 3c78e0d8947a
Write docker componse file. Edit docker file and add some commands
FROM dockerhub.private.wso2.com/ubuntu
MAINTAINER test
//run in remote machine
RUN apt-get update && apt-get install apache2 apache2-utils -y
//copy something from local to remote machine
COPY run_apache.sh /var/www/
RUN chmod 755 /var/www/run_apache.sh
EXPOSE 80
//This will execute only when run time happens.
CMD ["/var/www/run_apache.sh"]


Build docker from script file. here testapache is name and . means pick docker file from current location.
docker build -t testapache .
edit file
vim docker-compose.yml
up composed pattern
docker-compose up
Stop running deployment.
docker-compose down
Cleanup files.
docker rm -f $(docker ps -qa)

No comments:

Post a Comment

Empowering the Future of API Management: Unveiling the Journey of WSO2 API Platform for Kubernetes (APK) Project and the Anticipated Alpha Release

  Introduction In the ever-evolving realm of API management, our journey embarked on the APK project eight months ago, and now, with great a...