プログラミングBlog

【LPIC資格試験】Linuxコマンド確認用にdockerでLinux環境を構築する

用意するもの

vscode + 拡張機能remote-containers
marketplace.visualstudio.com
②Dockerに必要な環境
hub.docker.com

Centosを構築

Linuxコマンドを検証したいので、Linux環境を構築する。
公式のDockerfileをそのまま使用。

FROM centos:7
ENV container docker
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == \
systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;
VOLUME [ "/sys/fs/cgroup" ]
CMD ["/usr/sbin/init"]

hub.docker.com

buildがうまくいかない場合

unable to find user vscode: no matching entries in passwd file

remoteUseをrootに変更する。

変更前

  // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
    "remoteUser": "vscode"

変更後

  // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
    "remoteUser": "root"

コマンドが見つからない場合

bash: lspci: command not found

lspciコマンドに必要なpackage、pciutilsをinstallする。
DockerFileに必要なpackageを追加。

RUN yum -y install pciutils

感想

ローカル環境に何も追加していないため、後片付けが楽。
コマンド確認もできるので良い。