Install git inside a container and establish remote connection using VSCode. Incorporating Docker containers into actual development has become easier for development and version control purposes. I have shared the knowledge gained from creating this application in a Qiita post.
In my environment, I have installed Docker on Ubuntu. It is assumed that you can connect to GitHub via SSH using VSCode.
__β» I received a report from someone who helped with the verification process that Rootless Mode is required to use Docker with VSCode. __ I will update with additional information if available.
Tool | Version | Remarks |
---|---|---|
Docker | 20.10.21 | |
docker-compose | 1.29.2 | |
Dev Containers | 0.266.1 | VSCode extension |
root/
β .devcontainer/
β β devcontainer.json
β templates/
β β index.html
β .dockerignore
β Dockerfile
β docker-compose.yml
β .gitignore
β app.py
β requirements.txt
β» The installation of each tool has been completed.
-
Clone the SampleTodo repository from this repository.
git clone git@github.com:workshop-msano/sampleTodo.git
-
Open the files in VSCode. Press the Remote Container start button at the bottom left of VSCode.
- Select
Open Folder in Container
from the popup window in VSCode.
- Click
Open
in the popup window.
- After a while, VSCode will be displayed. If
Dev Container
is displayed next to the Remote Development button at the bottom left, it means it was successful!
- You can access the web app from
http://localhost:8000
.
Since git is already installed in the container, configure it to access GitHub from the container. Open the terminal and run the following commands.
It is assumed that you can connect to GitHub via SSH using VSCode.
git config --global user.email '<your setting>'
git config --global user.name '<Your setting>'
mkdir -p ~/.ssh/
curl -s -o ~/.ssh/id_ed25519 "https://github.com/$(git config --global --get user.name).keys"
Next, enter ssh -v git@github.com
in the terminal.
If there is a successful access to GitHub displayed in the log, it is complete! You can create a repository on GitHub and manage the source code version from within the Docker container.
Let's use a shell script to access the database in the Docker container. Execute the following commands outside the container.
docker exec -it sampletodo_db /bin/sh
psql --username postgres