Skip to content

🐳 Installing and Running Docker in WSL with VS Code¢

WSL is much more integration and user friendly.

Install Docker

Docker Settings:ΒΆ

Docker Docker

Run docker from WSL LinuxΒΆ

Docker

Connect to container via VS CodeΒΆ

Docker

CommandsΒΆ

Command Description
docker ps List all containers
docker ps -a
docker stop id for id first num or char should be enough if no duplicate
docker rm id
docker images
docker rmi id
docker inspect containerName Give all the details about the container
docker rm –v id Remove container and volume
Command Description
docker-compose build Build or rebuild services defined in docker-compose.yml
One off command (only mongo) docker-compose build mongo
docker-compose up Create and start the containers
docker-compose up –no-deps node
--no-deps: Do not recreate services that node depends on node:
Rebuild node image and stop, destroy and recreate only node
docker-compose up –d : in daemon mode, so it won’t block the console
docker-compose down down: Take all of the containers down (stop and remove)
docker-compose down –rmi all –volumes --rmi
:Remove all images --volumes: Remove all volumes
docker-compose logs
docker-compose ps
docker-compose stop
docker-compose start
docker-compose rm
Command Description
docker rm $(docker ps -a -q) Delete all containers
docker rmi $(docker images -q) Delete all images
docker rm –f $(docker ps –a -q) Remove all containers
-f: force
-q: quite
docker rmi -f $( docker images -q dangling=true) docker rmi -f $( docker images -q)

Example

Text Only
`docker pull kitematic/hello-world-nginx`

`docker run –p 80:80 kitematic/hello-world-nginx` 
With part mapping - 80 image port to 80 container port

`docker run  -p 8080:3000 –v /var/www node`
where –v creates volume and /var/www is container volume on host. We can check about the location of container volume using command

We can customize the volume location rather than default. docker run -p 8080:3000 –v $(pwd) /var/www node where $(pwd) is from current working directory used as host location (or host mount) 8080: external or image port 3000: default port the express generated so we need to use that as internal port -v: create volume $(pwd): Create volume that point source code in current directory /var/www: volume inside the container that points to current directory -w: make β€œ/var/www” as working directory or context to run commands

Tip

Text Only
Set timezone in ubuntu

console RUN apt-get update && \ apt-get install -yq tzdata && \ ln -fs /usr/share/zoneinfo/America/New_York /etc/localtime

Tip

Text Only
Get all containers and it's ports
`docker container ls --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}" -a`