2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【VSCode】bashのコマンド履歴を永続化する方法【Remote - Containers】

Last updated at Posted at 2022-05-23

Remote - Containers使用時にbashの履歴を永続化する方法

Dockerfileを編集する

Dockerfileに以下を追記します。

ユーザーがrootの場合

RUN SNIPPET="export PROMPT_COMMAND='history -a' && export HISTFILE=/commandhistory/.bash_history" \
    && echo $SNIPPET >> "/root/.bashrc"

ユーザーがroot以外の場合

ARG USERNAME=ユーザー名
RUN SNIPPET="export PROMPT_COMMAND='history -a' && export HISTFILE=/commandhistory/.bash_history" \
    && mkdir /commandhistory \
    && touch /commandhistory/.bash_history \
    && chown -R $USERNAME /commandhistory \
    && echo $SNIPPET >> "/home/$USERNAME/.bashrc"

docker-compose.ymlを編集する

docker-compose.ymlを使用している場合には以下を追記します。

docker-compose.yml
volumes:
      - projectname-bashhistory:/commandhistory

volumes:
  projectname-bashhistory:

devcontainer.jsonを編集する

docker-compose.ymlを使用していない場合にはdevcontainer.jsonに以下を追記します。

devcontainer.json
"mounts": [
      "source=projectname-bashhistory,target=/commandhistory,type=volume"
  ]
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?