Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dockerfile don't support .bashrc environment variable #395

Closed
1 of 3 tasks
zjb0807 opened this issue Aug 9, 2018 · 4 comments
Closed
1 of 3 tasks

dockerfile don't support .bashrc environment variable #395

zjb0807 opened this issue Aug 9, 2018 · 4 comments

Comments

@zjb0807
Copy link

zjb0807 commented Aug 9, 2018

  • This is a bug report
  • This is a feature request
  • I searched existing issues before opening this one

Dockerfile:

FROM ubuntu

RUN echo 'export GOROOT=/root/go' >> /root/.bashrc && \
    /bin/bash -c 'source /root/.bashrc && echo $GOROOT'

When i build images, echo $GOROOT will Printout empty, but if i change the dockerfile like this:

FROM ubuntu

RUN echo 'export GOROOT=/root/go' >> /root/bashrc && \
    /bin/bash -c 'source /root/bashrc && echo $GOROOT'

echo $GOROOT will Printout /root/go

Expected behavior

# docker build --no-cache -t test .
Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM ubuntu
 ---> 735f80812f90
Step 2/2 : RUN echo 'export GOROOT=/root/go' >> /root/bashrc &&     /bin/bash -c 'source /root/bashrc && echo $GOROOT'
 ---> Running in de6fef00ad5e
/root/go
Removing intermediate container de6fef00ad5e
 ---> 4c43192410df
Successfully built 4c43192410df
Successfully tagged test:latest

Actual behavior

# docker build --no-cache -t test .
Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM ubuntu
 ---> 735f80812f90
Step 2/2 : RUN echo 'export GOROOT=/root/go' >> /root/.bashrc &&     /bin/bash -c 'source /root/.bashrc && echo $GOROOT'
 ---> Running in 5a4e9c4fb915

Removing intermediate container 5a4e9c4fb915
 ---> 3e9d88bcc1b1
Successfully built 3e9d88bcc1b1
Successfully tagged test:latest

Steps to reproduce the behavior

Output of docker version:

# docker version
Client:
 Version:           18.06.0-ce
 API version:       1.38
 Go version:        go1.10.3
 Git commit:        0ffa825
 Built:             Wed Jul 18 19:11:02 2018
 OS/Arch:           linux/amd64
 Experimental:      false

Server:
 Engine:
  Version:          18.06.0-ce
  API version:      1.38 (minimum version 1.12)
  Go version:       go1.10.3
  Git commit:       0ffa825
  Built:            Wed Jul 18 19:09:05 2018
  OS/Arch:          linux/amd64
  Experimental:     false

Output of docker info:

# docker version
Client:
 Version:           18.06.0-ce
 API version:       1.38
 Go version:        go1.10.3
 Git commit:        0ffa825
 Built:             Wed Jul 18 19:11:02 2018
 OS/Arch:           linux/amd64
 Experimental:      false

Server:
 Engine:
  Version:          18.06.0-ce
  API version:      1.38 (minimum version 1.12)
  Go version:       go1.10.3
  Git commit:       0ffa825
  Built:            Wed Jul 18 19:09:05 2018
  OS/Arch:          linux/amd64
  Experimental:     false
root@iZj6ccusv1f4owdo0s9szyZ:~/nes/3# docker info
Containers: 39
 Running: 2
 Paused: 0
 Stopped: 37
Images: 89
Server Version: 18.06.0-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: d64c661f1d51c48782c9cec8fda7604785f93587
runc version: 69663f0bd4b60df09991c08812a60108003fa340
init version: fec3683
Security Options:
 apparmor
 seccomp
  Profile: default
Kernel Version: 4.15.0-24-lowlatency
Operating System: Ubuntu 16.04.5 LTS
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 7.789GiB
Name: iZj6ccusv1f4owdo0s9szyZ
ID: 4N46:JD4L:GRWZ:SFHH:3JJS:AJ4G:SX3D:E7QE:QVWF:5P7L:JFOC:RJFL
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Username: zjb0807
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

WARNING: No swap limit support

Additional environment details (AWS, VirtualBox, physical, etc.)
Aliyun ECS(Elastic Compute Service) , just like AWS

@seemethere
Copy link

Do you need to define GOROOT through your .bashrc?

Wouldn't it be better to define it as an ENV directive?

FROM ubuntu
ENV GOROOT /root/go
RUN echo ${GOROOT}

@zjb0807
Copy link
Author

zjb0807 commented Aug 9, 2018

I know this,I just want to know why the /root/.bashrc file doesn't work, but the /root/bashrc file does

@seemethere
Copy link

The problem still exists even in a basic VM:

vagrant@ubuntu-bionic:~$ echo 'export GOROOT=$HOME/go' >> $HOME/.bashrc &&     /bin/bash -c 'source $HOME/.bashrc && echo $GOROOT'

This doesn't appear to be an issue with docker so I'm going to close this but I am curious as to why it doesn't work.

@46319943
Copy link

Maybe It's because you are not running interactively when use /bin/bash -c 'source xxx'.
In the first few line of .bashrc, it writes

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

So, when use /bin/bash -c 'source xxx', it return immediately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants