Git Product home page Git Product logo

docker-practice's People

Contributors

suzuki-hoge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

docker-practice's Issues

「起動中のコンテナ内でコマンドを実行する」でファイルの存在が確認できません。

有用な書籍の公開ありがとうございます。

起動中のコンテナ内でコマンドを実行する
https://zenn.dev/suzuki_hoge/books/2022-03-docker-practice-8ae36c33424b59/viewer/2-6-container-exec#%E8%B5%B7%E5%8B%95%E4%B8%AD%E3%81%AE%E3%82%B3%E3%83%B3%E3%83%86%E3%83%8A%E5%86%85%E3%81%A7%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E3%82%92%E5%AE%9F%E8%A1%8C%E3%81%99%E3%82%8B

書籍の手順に沿って操作したつもりですが、ファイルの存在を確認できませんでした。

私はどこを理解できていませんか?
ご教示くだされば幸いです。

実行環境: Ubuntu20.04を使用

$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.5 LTS"

$ docker --version 
Docker version 20.10.18, build b40c2f6

操作

ターミナルにて

// コンテナが存在しないことを確認
$ docker container ls -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

$ docker container run \
    --name ubuntu1     \
    --rm               \
    --interactive      \
    --tty              \
    ubuntu:20.04

root@fe5fd49c4bcf:/# echo 'hello world' > ~/hello.txt
root@fe5fd49c4bcf:/# 

同一ターミナルにタブを追加して

// コンテナの状況を確認 `CONTAINER ID`, `NAME` 共にOK
$ docker container ls -a
CONTAINER ID   IMAGE          COMMAND   CREATED          STATUS          PORTS     NAMES
fe5fd49c4bcf   ubuntu:20.04   "bash"    27 seconds ago   Up 26 seconds             ubuntu1

// NAMESに合わせて...
$ docker container exec \
>     ubuntu1             \
>     cat ~/hello.txt
cat: /home/loginname/hello.txt: No such file or directory

CONTAINER ID でも結果は同様です。

$ docker container exec fe5fd49c4bcf cat ~/hello.txt
cat: /home/loginname/hello.txt: No such file or directory

No such file or directory
ファイルの存在を確認できません。

最初のターミナルタブに戻ってファイルを確認すると存在しています。

root@fe5fd49c4bcf:/# cat ~/hello.txt 
hello world

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.