π³ Installing and Running Docker in WSL with VS CodeΒΆ
WSL is much more integration and user friendly.
Docker Settings:ΒΆ
Run docker from WSL LinuxΒΆ
Connect to container via VS CodeΒΆ
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`