docker commit sql_2019 sqlImage
The commit command will save a container to an image.
Where
- sql_2019 - this is the name of a running container
- sqlImage - is the name of the image that it will create
docker compose up -d
The compose up command will tell Docker to look for a file named compose.yml, and build a set of containers based upon a collection of services listed in that file. Each service is instructions for another container.
docker container rm SQLServer2019
This command will remove the container (it will leave behind the image)
Where
- SQLServer2019 - is the name of the container used when the container was started (or run’d)
Note: You must stop the container before you can remove it
docker container run –name SQLServer2019 -p 1433:1433 -e “ACCEPT_EULA=Y” -e “SA_PASSWORD=SecretPassword” -p 1436:1433 -d mcr.microsoft.com/mssql/server:2019-latest
This command is similar to the docker run, but it specifically says to run a container. See ‘Docker Run’ for instructions on the different parameters
docker container start sql_2019
This command will stop a container that was stopped earlier.
The arguments used by the originating docker run command will be applied to the start command.
docker container stop sql_2019
This command will stop a container currently running.
Where
- sql_2019 - this is the NAMES of the container running, you can use docker ps -a to get the container name.
Note: We used the container name, but you can also use a CONTAINER ID (shown as the first column of docker ps -a).
Note: When you stop the container, the contents of it’s file system are persisted, and available when you later start the container.
docker cp bu.bak sql_2019:/d/data/checkbook.bak
This will copy a file called bu.bak into a container called sql_2019, it will add it into the /d/data directory and name the file checkbook.bak
docker exec -it sql_2019 /opt/mssql-tools/bin/sqlcmd -S localhost -U sa
This command executes a command that is inside the container.
Where
- -it sql_2019 - this says you want interactive access - like you want to see the C Prompt. sql_2019 is the name of the container that you want to access.
- /opt/mssql-tools/bin/sqlcmd - this is the command you want to execute. In this case sqlcmd is a program that comes with SQL Server that allows you to execute SQL statements via the command prompt.
- -S localhost ?????
- -U sa ?????
docker image ls
This command gives you a list of images on your computer. That’s like a hard drive copy of the container, which get’s loaded into memory and is then called a container.
docker inspect CheckbookDb
This gives you information about a volume named CheckbookDb
You can also inspect an image.
docker login
Use this command to log into docker. You will be prompted for a Username and a Password.
I’m not sure why it is nessesary to log into docker, however earlier research had me thinking I cannot create a docker image unless I have logged in. Actually one of the secrets to Docker is that you start off with a prebuilt container
docker logs SqlCheckbookPrep
Use this command to display a log file associated with the container you are referring to
Where
- SqlCheckbookPrep - this is the name of a container, it could also be a CONTAINER ID
docker pull mcr.microsoft.com/mssql/server:2019-latest
This will download an image down to your computer. Some of these images are fairly large and may take awhile to download.
Where
- mcr.microsoft.com/mssql/server:2019-latest - this is the name of the image to download.
docker run -d -p 81:80 docker/getting-started
Another sample
docker run –name sql_2019 -e “ACCEPT_EULA=Y” -e “SA_PASSWORD=SecretPassword” -p 1436:1433 -d mcr.microsoft.com/mssql/server:2019-latest
This launches a docker container.
Where
- -d - run it in the background
- -e “ACCEPT_EULA=Y” - this will set an environmental variable in the container. In this case ACCEPT_EULA is the environmental variable, Y is the value of that variable.
- -p 81:80 - we communicate to this image through port 81. Commands going to this port will be directed into the container’s port 80.
- -v externalLocation:internalLocation (for example -v c:\t:\data) allows you to map a directory of your computer to a location within the container. In the case of c:\t - we are using our c:\t directory - and handing it over to the container to use as \data
- –name sql_2019 - this is the name we want to give the container. In this case the name given is sql_2019
- docker/getting-started - this is the name of a container. If it doesn’t exist then the command will download the image from docker hub.
docker run -it -v demo_volume:/data ubuntu:22.04
docker ps
This gives you a list of running containers
command starts a new Ubuntu 22.04 container and attaches your terminal to it (-it), ready to run demonstration commands in the following steps
docker ps -a
This returns a list of images - pretty much all of them. Shows the ones that have run, were created, and that are running
docker push wachdorfm/SqlCheckbook:2019_1.00
This command copies an image that has been tagged with wachdorfm/SqlCheckbook:2019_1.00 up to docker hub.
You’ll notice multiple layers will be uploaded.
In theory people pulling this down, will only need to download the layers they dont have.
docker scout quickview
Presents a small table showing the layers of images, and the number of vulnerabilities in each.
docker scout recommendations welcome-to-docker:latest
presents a larger table
docker tag SqlImage wachdorfm/SqlCheckbook:2019_1.00
This will add some sort of stamp to an image. It’s used to prepare an image to be uploaded to docker hub.
Use Docker Push to upload
docker volume ls
Gives you a list of volumes created on your computer.