docker run -d -p 80:80 <image name>
-d runs container in detached mode (in the background)-p 80:80 maps port 80 of host to port 80 in container-dp)docker build -t <DockerFile> .
-t tags the image. tells Docker to look for DockerFile in current directorydocker ps
docker stop <container-id>
docker start <container-id>
docker rm <container-id>
docker rm -f <container-id>
-f force stops and removesdocker push <remote repo>/<image>
docker login -u <username>
docker tag <old name> <new name>
docker volume create <volume name>
# Using tutorial example
docker run -dp 3000:3000 -v todo-db:/etc/todos getting-started
-v specifies the volume mountdocker run -dp 3000:3000 `
-w /app -v "$(pwd):/app" `
node:18-alpine
sh -c "yarn install && yarn run dev"
-w /app sets the container's present working directory where the command will run from-v "$(pwd):/app" bindmount the host's present getting-started/app directory to the container's /app directorydocker logs -f <container-id>
docker compose up -d
docker compose down --volumes
--volumes removes volumes along with containerdocker compose up --build
--build shows logs while containers are being built\wsl.localhost\docker-desktop\mnt\docker-desktop-disk\data\docker\volumes
docker exec -it <container> /bin/sh
docker exec -it <container> /bin/bash
docker exec -it <container> /bin/ash #Use this for Alpine images
docker exec -it <container> /bin/dash
-i for interactive-t for terminaldocker exec <container> <command>
docker run <image> bash -c <command>
docker run -d <image> bash -c "sleep 1000"
# Using Ubuntu as example
docker run ubuntu sh -c "cat /etc/*release*" | grep VERSION
docker run <image>:<tag>
docker pull mcr.microsoft.com/mssql/server
docker run --name sql-server-db -d -p 1433:1433 -e MSSQL_SA_PASSWORD=<password> -e ACCEPT_EULA=Y <image>
Tried 'SA_PASSWORD' but this caused an OBDC error when trying to access sqlcmd inside container.
docker exec -it <container> bash
/opt/mssql-tools18/bin/sqlcmd \
> -S localhost \
> -U sa \
> -P <password> \
> -C
--Show databases
1> SELECT name
2> FROM sys.databases;
3> GO
--Create Database
1> CREATE DATABASE Homedb;
2> GO
--Set new database as current db
1> USE Homedb;
2> GO
--Create table
1> CREATE TABLE apprepo (
2> AppID INT PRIMARY KEY,
3> AppName VARCHAR(255),
4> Path VARCHAR(255),
5> Arguments VARCHAR(255));
6> GO
--Insert data
1> INSERT INTO apprepo
2> VALUES (1, '7-ZIP', '\\Path\\To\\7-ZIP', '\/S');
3> GO
--Show tables
1> SELECT name
2> FROM sys.tables;
3> GO
docker exec -it <container-name> bash
# Run in open shell
mysql -p
-p wil prompt for password-u for User, the command will use rootSHOW databases;
USE <database>;
SHOW tables;
# docker-compose.yml
services:
sql-server-db:
container_name: sql-server-db
image: mcr.microsoft.com/mssql/server:latest
ports:
- "1433:1433"
environment:
MSSQL_SA_PASSWORD: <password>
ACCEPT_EULA: "Y"
volumes: - ./sql-server-data:/var/opt/mssql/data
docker compose up -d