Create a Docker container to run VS Code for use as a development environment. It will be executed as follows.
--VSCode starts as a GUI app when you start the container --The user who starts VS Code is specified when creating the container.
It is assumed that the container image is created based on the article Running GUI application on Docker container (Japanese input).
Dockerfile
FROM sabocla6/ubuntu_ui_jp
# ***********************************************
# install packages for xrdp, and do setting
# ***********************************************
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
gnupg firefox supervisor
# ***********************************************
# prepare add user
# ***********************************************
RUN chmod u+s /usr/sbin/useradd \
&& chmod u+s /usr/sbin/groupadd \
&& chmod u+s /usr/sbin/chpasswd
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN echo "ALL ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/ALL
# ***********************************************
# install vscode
# ***********************************************
ADD https://az764295.vo.msecnd.net/stable/ea3859d4ba2f3e577a159bc91e3074c5d85c0523/code_1.52.1-1608136922_amd64.deb /tmp/code.deb
RUN dpkg -i /tmp/code.deb
# ***********************************************
# copy entrypoint shell
# ***********************************************
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["docker-entrypoint.sh"]
docker-entrypoint.sh
#!/bin/bash -e
USER_ID=$(id -u)
GROUP_ID=$(id -g)
USER=${USER:-${DEFAULT_USER}}
GROUP=${GROUP:-${USER}}
PASSWD=${PASSWD:-${DEFAULT_PASSWD}}
NeW_USER=false
unset DEFAULT_USER DEFAULT_PASSWD
# Add group
echo ""
if [[ $GROUP_ID != "0" && ! $(getent group $GROUP) ]]; then
echo "Create New Group GROUP_ID: $GROUP_ID GROUP: $GROUP"
groupadd -g $GROUP_ID $GROUP
fi
# Add user
if [[ $USER_ID != "0" && ! $(getent passwd $USER) ]]; then
echo "Create New User USER_ID: $USER_ID USER: $USER"
export HOME=/home/$USER
useradd -d ${HOME} -m -s /bin/bash -u $USER_ID -g $GROUP_ID -G 27 $USER
NeW_USER=true
fi
# Set login user name
USER=$(whoami)
echo "USER: $USER"
# Set login password
echo "PASSWD: $PASSWD"
echo ${USER}:${PASSWD} | sudo chpasswd
# Revert permissions
sudo chmod u-s /usr/sbin/useradd
sudo chmod u-s /usr/sbin/groupadd
sudo chmod u-s /usr/sbin/chpasswd
unset PASSWD
if [[ "$@" = "" ]]; then
exec /bin/bash
else
exec "$@"
fi
sudo docker build ./ -t sabocl6/vscode
Since there are many options that must be specified, start using docker-compose.
docker-compose.yml
version: "3.3"
services:
devmachine:
image: sabocla6/vscode
volumes:
- $HOME/.Xauthority:/root/.Xauthority
user: "1000:1000"
shm_size: '2G'
network_mode: "host"
privileged: true
environment:
USER: sabocla6
PASSWD: passwd
DISPLAY: $DISPLAY
command: code -w
Start command
sudo docker-compose up
Run GUI application on Docker container (Japanese input) Run GUI application on Docker container
For user creation, refer to Building a desktop environment where uid/gid can be specified and sudo can be used with Docker (XRDP).
Recommended Posts