bashの操作ログを永続化する
Docker
Dockerfile
FROM node:16.15.0
ENV TZ=Asia/Tokyo
ARG USERNAME=node
RUN corepack enable npm
RUN SNIPPET='\n if [ "$SHLVL" = "2" ] ; then \n \
\t script -f /bashlog/script/`date "+%Y%m%d%H%M%S"`.log \n \
fi \n \
\n export PROMPT_COMMAND="history -a" && export HISTFILE=/bashlog/.bash_history \n' \
&& mkdir -p /bashlog/script\
&& touch /bashlog/.bash_history \
&& chown -R ${USERNAME} /bashlog \
&& echo ${SNIPPET} >> "/home/${USERNAME}/.bashrc"
USER ${USERNAME}
RUN mkdir -p /home/${USERNAME}/.vscode-server/extensions
WORKDIR /myapp-frontend
EXPOSE 3000
/docker-compose.yml
version: '3.9'
services:
frontend:
build: .
volumes:
- sources:/myapp-frontend
- bashlog:/bashlog
- vscode-extensions:/home/node/.vscode-server/extensions
environment:
NODE_ENV: development
ports:
- 3000:3000
- 9229:9229
command: /bin/sh -c "while sleep 1000; do :; done"
volumes:
sources:
bashlog:
vscode-extensions:
Remote-Containers
.devcontainer/devcontainer.json
{
"name": "myapp-frontend",
"dockerComposeFile": ["../docker-compose.yml"],
"service": "frontend",
"workspaceFolder": "/myapp-frontend",
"customizations": {
"vscode": {
"extensions": [
"EditorConfig.EditorConfig",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"VisualStudioExptTeam.vscodeintellicode",
"arcanis.vscode-zipfs",
"bradlc.vscode-tailwindcss"
]
}
}
}