First, we will bootstrap our Python Flask project.
- Checkout this repo locally where you have VS Code installed
git clone https://github.com/thebyteio/vs-code-docker-training.git
- Open VS Code
- Open a New Terminal by going to VS Code Menu
Terminal -> New Terminal
- Navigate to the
04-power-user
foldercd 04-power-user
- Open the Command Palette
Mac ⇧⌘P
Windows CTRL + SHIFT + P
- Type in the Command Palette
Docker Add Docker files to workspace
- Choose
Python Flask
as application type - Application entrypoint is
04-power-user/app.py
- Port
5000
- Include optional Docker Compose files?
YES
Next, we will start our newly created Docker bootstrapped application.
- Right Click on
docker-compose.yml
and selectcompose up
- Next, click the Docker Extension icon (The Docker whale in the right toolbar)
- You should now see our vscode demo application as a running container
- Right click the
vscodedockertraining
and selectOpen in a Browser
- Test the different options available with the container
- Right click the
vscodedockertraining
and selectView Logs
- Right click the
vscodedockertraining
and selectInspect
- Try the rest Stop, Start, Restart, attach to the shell
Now, head back to File explorer which is the file icon in the top left
- Right click on the
Dockerfile
and selectBuild Image
- Choose the name of the image and tag
We finished working with our Cat GIF application so now it is time to cleanup.
- Right click on
docker-compose.yml
and selectCompose Down
Now, we will create a blank Dockerfile and fill in the Dockerfile using command completion and query Docker Hub
- Create a new file in the
04-power-user/app.py
directory calledDockerfile
- First line type:
FRO
and typeCTRL+Space
to see the command completion - Select,
FROM
- Now type the image name with just the first characters
alp
and againCTRL + Space
to get command completion to get the image namealpine
and click on the top image to use the official image - Now query the tags from Docker Hub by typing
alpine:
and againCTRL + Space
to query the image tags - Type the below Dockerfile
- Final line type
CM
and againCTRL + Space
to get theCMD
command completion
FROM alpine:3.12
RUN apk add --no-cache mysql-client
CMD [ "mysql" ]
Using the docker context
feature we can connect to remote Docker hosts. In this demo we start a container running Docker in Docker (DND). We can then connect to the DND container and launch containers inside the DND container completely separated from our original environment.
- Start Docker in Docker
docker run --rm -d -p 2375:2375 --privileged -e "DOCKER_TLS_CERTDIR=" --name dind docker:19.03-dind
- Create context
docker context create dind --docker "host=tcp://127.0.0.1:2375" --default-stack-orchestrator swarm
- Open the Docker Extension
- Expand the
Contexts
section - Right click on
DIND
and clickuse
- Launch a test container inside the DND container:
docker container run --rm -tip 5000:5000 --name cats mikesir87/cats:1.0
- You should now see the Cats image and Cat container appear.