Step 1: Make sure your Windows 10 version is 2004 or later
- Select the Start button > Settings > System > About
- Under Windows Specifications, you will see which version of Windows 10 you’re running
- If your version is lower than 2004, go to Windows Update in your settings and update Windows
- If the v2004 update doesn't show up, you can use the Update Assistant to update Windows 10
Step 2: Getting your machine ready to use WSL 2
- Search for ‘’Turn Windows features on or off’ in your search bar on the bottom left of your screen
- Enable both ‘Virtual Machine Platform’ and ‘Windows Subsystem for Linux’
- Restart your computer
Step 3: Installing a Linux distribution on Windows 10
- You can install a Linux distribution from the Microsoft store, in this tutorial we will be using ‘Ubuntu 18.04 LTS’
- Once the Linux distribution has been installed, start it up
- You will be asked to create a username and password when you launch Linux for the first time, these have no bearing on your windows system so choose whatever you want!
- You can now close the application
Step 4: Using WSL2 to run your Linux distribution
- Make sure you have the latest version of WSL 2 installed by running the update package found here;
- Open WindowsPowerShell
- Run
wsl -l
to list the Ubuntu distributions you currently have installed, you should see ‘Ubuntu-18.04’ in the list - Set the WSL version for Ubuntu 18.04 by running
wsl --set-version Ubuntu-18.04 2
(The 2 at the end is very important because it tells your machine you want to use WSL2) - You can check that you successfully switch to wsl 2 by running
wsl -l -v
Additionally, if you want to make WSL 2 your default architecture you can do so with this command:
wsl --set-default-version 2
Step 5: Installing Docker on Windows 10
- Download the latest release of Docker Desktop
- Follow the usual installation instructions to install Docker Desktop
- Start Docker Desktop from the Windows Start menu
- From the Docker menu, select Settings > General
- Make sure that ‘Use the WSL 2 base engine’ is selected. If it wasn’t, select it and click Apply & Restart
- Now go to go to Settings > Resources > WSL Integration in Docker and select your Linux distribution (Ubuntu 18.04 in this tutorial)
- Enable the Docker integration with the kernel you installed (Ubuntu 18.04) and click Apply and restart
Step 6: Using Docker in Windows 10
- To use Docker in your distribution, Docker Desktop has to be running
- Launch your distribution (Ubuntu 18.04 LTS in this tutorial)
- Run ‘docker version’ to check that Docker is running and accessible
Monitoring commands:
These few commands are in my mind the first you need to know when using Docker.
docker ps (-a)
docker ps displays every docker instance currently running in your environment. If you add the -a option, then you even have the stopped ones.
docker images (-a)
The docker images show to you the images you have build, and the -a show you the intermediate images.
docker network ls
docker-compose ps
The docker network ls list the networks and docker-compose ps displays all the containers once started with it (currently running or not).
Manage commands:
You now need images and containers to test the few previous commands.
docker-compose up (-d) (--build)
docker-compose stop
The docker-compose is easiest because you only need 2 commands: up and stop. stop is explicit and stop (not remove) your containers, but up require more explanations: it will build your images if they aren't already and will start your dockers. If you want to re-build your images, use the option --build (you can also use the command docker-compose build to only build the images). The option -d, which means "detach" make the containers run in the background.
docker build (-t <NAME>) <PATH>/<URL>
With Docker, you need a separate command to build your image where you can specify the name of your image and you have to specify the PATH or URL to your context (this can be a git repository).
docker run (-d) (-p <hostPort>:<containerPort>) (--name <NAME>) <IMGNAME>/<IMGID>
run create the container using the image you tell it. You can specify lots of parameters, I recommend you to add a name to your container and you may need to specify some ports to expose. As for docker-compose, the -d make the container run in the background.
docker start <ID>/<NAME>
docker stop <ID>/<NAME>
The start and stop shouldn’t be hard to understand, but you have to note that you can only start containers already stopped, this means already built with run.
docker exec -it <NAME>/<ID> <“sh”>/<”/bin/bash”>
This command allows you to connect to the shell of your container. I prefer using "/bin/bash" but your container may not have bash installed and only "sh" which is more common. If you put some special configuration to your container, you may need to use extra arguments to connect to it. This command can do much more than this, I recommend to read the doc for further information.
Remove commands:
These commands remove your containers and images, you will likely need them to save disk space.
docker rm <ID>/<NAME>
docker-compose rm
The docker rm remove only one container when docker-compose rm remove every container started with a docker-compose command.
docker rmi <ID>/<NAME>
docker rmi delete the image you give as a parameter and recursively all the images intermediate used to build it.
Logs commands:
The commands below are useful when you need to debug some of your containers (or more often the applications you deploy in it).
docker logs <ID>/<NAME> (-f --tail <NBLINE>)
This command prints you the logs of the container you specify. If you use the option -f --tail <NBLINE> you can follow the live flux of your logs (<NBLINE> is the number of lines you want to display. Keep in mind to choose a number of lines you can handle and to not be overwhelmed by your logs).
docker-compose logs (<ID>/<NAME>)
The option (<ID>/<NAME>) with the docker-compose logs let you see the logs from only one container instead of every logs. The point here is if you don’t use the -d option when using docker run or docker-compose up you will see your logs directly (but you will need to stop the container to quit the view). It can still be useful to debug launching apps.
No comments:
Post a Comment