0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Dockerコマンドがsudoなしで実行しなかった話(解決済)

Last updated at Posted at 2024-08-05

これはなに?

色々あってDockerを再構築したらsudoでしかコマンド実行できなかった問題と対策について備忘録として示す。

最初にしたこと

DockerとDocker Desktop for Linuxをインストールしてdockerグループを作成しユーザを所属させた。

直面した問題

何やっても Is the docker daemon running?

gpasswd -a $USER dockerしようが何しようがうまくいかない。ユーザもおかしい。

$ docker images
Cannot connect to the Docker daemon at unix:///run/user/1000/docker.sock. Is the docker daemon running?

気づいたこと

Docker Desktopにイメージが反映されてない。

$ sudo docker images
REPOSITORY                                        TAG             IMAGE ID       CREATED         SIZE
ghcr.io/automotiveaichallenge/autoware-universe   humble-latest   30c59f3fb415   3 months ago    8.84GB
hello-world                                       latest          d2c94e258dcb   15 months ago   13.3kB

Screenshot from 2024-08-06 03-24-18.png

原因究明及び解決案

docker context

Docker Desktop が正しいコンテキストを使用していないと考えて確認しました。

$ docker context ls
NAME                TYPE                DESCRIPTION                               DOCKER ENDPOINT                                       KUBERNETES ENDPOINT   ORCHESTRATOR
default *           moby                Current DOCKER_HOST based configuration   unix:///run/user/1000/docker.sock                                           
desktop-linux       moby                Docker Desktop                            unix:///home/herniababy/.docker/desktop/docker.sock 

やっぱりね。コンテキストを切り替えます。

$ docker context use desktop-linux
desktop-linux
Current context is now "desktop-linux"
Warning: DOCKER_HOST environment variable overrides the active context. To use "desktop-linux", either set the global --context flag, or unset DOCKER_HOST environment variable.

怒られました。

DOCKER_HOST 環境変数を解除

DOCKER_HOST 環境変数がアクティブなコンテキストを上書きしています。
desktop-linux コンテキストを使用するには環境変数を解除する必要があります。

$ unset DOCKER_HOST
$ docker context ls
NAME                TYPE                DESCRIPTION                               DOCKER ENDPOINT                                       KUBERNETES ENDPOINT   ORCHESTRATOR
default             moby                Current DOCKER_HOST based configuration   unix:///var/run/docker.sock                                                 
desktop-linux *     moby                Docker Desktop                            unix:///home/herniababy/.docker/desktop/docker.sock                         

切り替えられました。

確認

sudoなしでの実行

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete 
Digest: sha256:1408fec50309afee38f3535383f5b09419e6dc0925bc69891e79d84cc4cdcec6
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

イメージの反映

$ docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    d2c94e258dcb   15 months ago   13.3kB

Screenshot from 2024-08-06 03-56-13.png

さいごに

Geminiを信じすぎてはいけない…

追記

defaultに残っていたイメージを消すためにコンテキスト戻して操作した結果

$ docker context use default 
default
Current context is now "default"

$ docker system prune -a
WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all images without at least one container associated to them
  - all build cache

Are you sure you want to continue? [y/N] y
(中略)

$ docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE

ハァ?

.bashrcの中身見たら

export PATH=/home/$(whoami)/bin:$PATH
export DOCKER_HOST=unix:///run/user/$(id -u)/docker.sock

原因これやん…

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?