0% found this document useful (0 votes)
33 views

Develop Intelligence - Docker Docker Commands: Agenda: Getting Started With Docker

This document discusses installing Docker for Windows 10/Mac and provides an overview of Docker commands. It describes downloading and installing Docker Desktop, verifying the Docker installation, listing Docker images, running containers, managing containers and images, and using Docker with .NET Core. Examples are provided for running Nginx, MySQL, and MSSQL Docker containers on local machines. Docker images for .NET Core SDK, runtime, and samples are also listed.

Uploaded by

saphana9800
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Develop Intelligence - Docker Docker Commands: Agenda: Getting Started With Docker

This document discusses installing Docker for Windows 10/Mac and provides an overview of Docker commands. It describes downloading and installing Docker Desktop, verifying the Docker installation, listing Docker images, running containers, managing containers and images, and using Docker with .NET Core. Examples are provided for running Nginx, MySQL, and MSSQL Docker containers on local machines. Docker images for .NET Core SDK, runtime, and samples are also listed.

Uploaded by

saphana9800
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Develop Intelligence – Docker Docker Commands

Agenda: Getting Started with Docker


 Installing Docker for Windows 10 Professional
 Docker Images for .NET Core.
 Docker CLI Commands
o Managing Images
o Managing Containers
 Creating Images from Container

Installing Docker for Windows 10 / Mac

 Docker for Windows is a Docker Community Edition (CE) app.


 The Docker for Windows install package includes everything you need to run Docker on a Windows system.
 Download link:
o Docker Desktop for Mac
 https://hub.docker.com/editions/community/docker-ce-desktop-mac
o Docker Desktop on Windows 10 Pro, Enterprise, and Education.
 https://hub.docker.com/editions/community/docker-ce-desktop-windows
o Docker Desktop on Windows 10 Home:
 https://docs.docker.com/docker-for-windows/install-windows-home/
 The installation provides Docker Engine, Docker CLI client, Docker Compose, Docker Machine, and Kitematic.

Note:
1. You can develop both Docker Linux containers and Docker Windows containers with Docker for Windows.
2. Virtualization must be enabled. You can verify that virtualization is enabled by checking the Performance tab
on the Task Manager.
3. The Docker for Windows installer automatically enables Hyper-V for you.
4. Containers and images created with Docker for Windows are shared between all user accounts on machines
where it is installed. This is because all Windows accounts use the same VM to build and run containers.
5. We can switch between Windows and Linux containers.

Play with Docker (PWD)


If your system does not meet the requirements to run Docker for Windows, You can use Play with Docker @
https://labs.play-with-docker.com/
PWD is a Docker playground which allows users to run Docker commands in a matter of seconds. It gives the
experience of having a free Alpine Linux Virtual Machine in browser, where you can build and run Docker
Develop Intelligence – Docker Docker Commands
containers and even create clusters. Under the hood Docker-in-Docker (DinD) is used to give the effect of multiple
VMs/PCs.

First, make sure the Docker installation is working correctly by running docker version. The output should tell you
the basic details about your Docker environment:

Make sure the Docker installation is working correctly by running docker version. The output should tell you the
basic details about your Docker environment.
Note: The OS/Arch field tells you the operating system you're using. Docker is cross-platform, so you can manage
Windows Docker servers from a Linux client and vice-versa, using the same docker commands.

To Change Docker Images Location:


For Windows / Mac Images:
Windows: c:\programdata\docker\config\daemon.json
Mac: ~/.docker/daemon.json
{ "graph": "e:\\images" }

In case Docker Engine is not starting on Windows 10, Run the following commands
1. https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi
2. wsl --set-default-version 2

Docker Commands
Listing all images from local registry:
 docker version
 docker pull hello-world
 docker pull nginx
 docker pull alpine
 docker pull ubuntu
 docker image history nginx
 docker inspect nginx
 docker images
 docker image ls
 docker images --no-trunc (List full lengh image IDs)
 docker images --filter=reference=alpine
Develop Intelligence – Docker Docker Commands
Some things to note:
1. IMAGE ID is the first 12 characters of the true identifier for an image. You can create many tags of a given
image, but their IDs will all be the same (as above).
2. VIRTUAL SIZE is virtual because it's adding up the sizes of all the distinct underlying layers. This means that the
sum of all the values in that column is probably much larger than the disk space used by all of those images.
3. The value in the REPOSITORY column comes from the -t flag of the docker build command, or from docker tag-
ing an existing image. You're free to tag images using a nomenclature that makes sense to you, but know that
docker will use the tag as the registry location in a docker push or docker pull.
4. The full form of a tag is [REGISTRYHOST/][USERNAME/]NAME[:TAG]. For ubuntu above, REGISTRYHOST is
inferred to be registry.hub.docker.com. So if you plan on storing your image called my-application in a registry
at docker.example.com, you should tag that image docker.example.com/my-application.
5. The TAG column is just the [:TAG] part of the full tag. This is unfortunate terminology.
6. The latest tag is not magical, it's simply the default tag when you don't specify a tag.
7. You can have untagged images only identifiable by their IMAGE IDs. These will get the <none> TAG and
REPOSITORY. It's easy to forget about them.

Basic Docker Commands:


1. docker pull hello-world
2. docker container run hello-world
3. docker ps
4. docker ps -a
5. docker run hello-world
6. docker run --name hello hello-world
7. docker rm <container-id>
8. docker run --rm hello-world
9. docker container prune
10. docker container prune --filter "until=24h" # To Remove all docker stopped containers older than 24
hours

11. docker run alpine ls -l


12. docker run alpine echo "Hello from Sandeep"
To create a container in Interactive Mode
13. docker run -it alpine /bin/sh
a. ls -l
b. echo "hello" > hello.txt
c. ls
Develop Intelligence – Docker Docker Commands
d. exit
14. docker ps -a
15. docker start <container ID>
16. docker attach <container ID>
Ctrl + P + Q to detach from the shell, switching to host.
17. docker top <container id> #Display the running processes of a container
18. docker exec <container> /bin/sh

To run a sample web application:


docker run -p 8001:80 nginx
# Start a new Terminal / Command Window
docker ps
docker inspect <container-id>
curl <container-ip> - Fails to connect because container is in network with WSL or Linux VM Host machine. And
NOT with our local machine.
curl localhost:8001

docker run -d --rm -p 8080:80 nginx


docker logs <container-id>
 -p publishes a port. The IIS image is built to allow traffic in on port 80. This maps port 8080 on the host to
port 80 in the container
 -d starts in detached mode, Docker runs the container in the background and monitors it

To get terminal access of a container in running state


For Linux: docker exec -it <containername> /bin/bash
For Windows: docker exec -it <containername> cmd.exe

If containers are run on Linux VM or WSL on Windows 10:


Develop Intelligence – Docker Docker Commands

If containers are run directly on Windows / Linux Machine:

Exec Lab
• Start a new container from the nginx image on Docker Hub
• Using exec, get into the container and have a look around
• Visit the web site and make sure you see the default home page.
• Now go change the home page index.html file located in /usr/share/nginx/html.
• Add file /usr/share/nginx/html/hello.html (use echo)
• Verify that your changes show in the web site.

Solution:
• docker run -p 8080:80 -d --rm nginx
• docker ps
• docker exec -it <container name> /bin/sh
• # cd /usr/share/nginx/html
• # echo "hello" > "hello.html"
• # exit
• curl http://localhost:8080/hello.html
• docker commit <container id> myngnix
Develop Intelligence – Docker Docker Commands
• docker run -p 8081:80 mynginx
• curl http://localhost:8081/hello.html

• docker diff <container-id>

LAB: MySQL Image


Let’s run a container of the MySql / SQL Server image on our local machines.
• Find the image on Docker Hub – review the instructions
• Run the image locally. Pass in environment variables to allow access to the database.
• If you have Mysql tools already installed on your workstation, try to connect, add some data.

Solution:
MSSQL Server
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=Password_*123" --name "sql-demo" -e
"MSSQL_PID=Developer" -d -p 1412:1433 -v db-data-sqlsrv:/var/opt/mssql mcr.microsoft.com/mssql/server:2019-
latest

MySQL Server
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=Password_*123 -d -p 3306:3306 -v db-data-
mysql:/var/lib/mysql mysql

Docker Images for .NET Core


Docker Images variations:
a) .NET Core SDK: mcr.microsoft.com/dotnet/sdk:5.0
b) .NET Core Runtime: mcr.microsoft.com/dotnet/runtime:5.0
Develop Intelligence – Docker Docker Commands
c) ASP.NET Core Runtime: mcr.microsoft.com/dotnet/aspnet:5.0
d) .NET Core Samples:
a. mcr.microsoft.com/dotnet/samples:dotnetapp
b. mcr.microsoft.com/dotnet/samples:aspnetapp

Learn about language-specific app development with Docker


 Docker for Java developers lab
 Port a node.js app to Docker lab
 Ruby on Rails app on Docker lab
 Dockerize a .Net Core application

You might also like