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

.withEnvironment() not working as expected #880

Closed
nilPPanda opened this issue Dec 5, 2024 · 2 comments
Closed

.withEnvironment() not working as expected #880

nilPPanda opened this issue Dec 5, 2024 · 2 comments

Comments

@nilPPanda
Copy link

Expected Behaviour
That .withEnvironment function add to the containers the environment variables specified

Actual Behaviour
.withEnvironment() not adding the environment variables to the container

Testcontainer Logs

Initializing testContainers...
  testcontainers:containers [75d9a049ef5c] 2024/12/05 17:11:33 Pinging Docker... +0ms
  testcontainers:containers [75d9a049ef5c] 2024/12/05 17:11:33 Docker daemon is available! +1ms
  testcontainers:containers [75d9a049ef5c] 2024/12/05 17:11:33 Starting on port 8080... +0ms
  testcontainers:containers [75d9a049ef5c] 2024/12/05 17:11:33 Started! +0ms
  testcontainers:containers [75d9a049ef5c] 2024/12/05 17:11:33 New client connected: 172.17.0.1:54314 +10ms
  testcontainers:containers [75d9a049ef5c] 2024/12/05 17:11:33 Adding {"label":{"org.testcontainers.session-id=eaf04502d39d":true}} +1ms
 testcontainers:containers [061655271c0a] MYSQL_PASSWORD=test +481ms
  testcontainers:containers [061655271c0a] 0=M +0ms
  testcontainers:containers [061655271c0a] 1=Y +0ms
  testcontainers:containers [061655271c0a] 2=S +0ms
  testcontainers:containers [061655271c0a] 3=Q +0ms
  testcontainers:containers [061655271c0a] 4=L +0ms
  testcontainers:containers [061655271c0a] 5=_ +0ms
  testcontainers:containers [061655271c0a] 6=H +0ms
  testcontainers:containers [061655271c0a] 7=O +0ms
  testcontainers:containers [061655271c0a] 8=S +0ms
  testcontainers:containers [061655271c0a] 9=T +0ms
  testcontainers:containers [061655271c0a] HOSTNAME=061655271c0a +0ms
  testcontainers:containers [061655271c0a] MYSQL_DATABASE=test +0ms
  testcontainers:containers [061655271c0a] 13=E +0ms
  testcontainers:containers [061655271c0a] 12=M +0ms
  testcontainers:containers [061655271c0a] 11=A +0ms
  testcontainers:containers [061655271c0a] 10=N +0ms
  testcontainers:containers [061655271c0a] MYSQL_ROOT_PASSWORD=test +0ms
  testcontainers:containers [061655271c0a] PWD=/ +0ms
  testcontainers:containers [061655271c0a] HOME=/root +0ms
  testcontainers:containers [061655271c0a] MYSQL_MAJOR=8.0 +0ms
  testcontainers:containers [061655271c0a] GOSU_VERSION=1.14 +0ms
  testcontainers:containers [061655271c0a] MYSQL_USER=test +0ms
  testcontainers:containers [061655271c0a] MYSQL_VERSION=8.0.31-1.el8 +0ms
  testcontainers:containers [061655271c0a] SHLVL=1 +0ms
  testcontainers:containers [061655271c0a] PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +0ms
  testcontainers:containers [061655271c0a] MYSQL_SHELL_VERSION=8.0.31-1.el8 +0ms
  testcontainers:containers [061655271c0a] _=/usr/bin/printenv +0ms

Steps to Reproduce
Define a simple container like this

const { MySqlContainer } = require('@testcontainers/mysql');

const mysqlContainer = await new MySqlContainer()
    .withRootPassword(sqlPassword)
    .withDatabase(sqlDB)
    .withEnvironment('MYSQL_HOSTNAME', sqlHostName) // Manually add the env var
    .withNetworkAliases(sqlHostName)
    .withExposedPorts(3306)
    .withReuse()
    .withCommand(['sh', '-c', 'printenv && sleep 10'])
    .start();
  • see the logs i shared, there is no MYSQL_HOSTNAME env var, happens in all my containers when adding env variables with this function, i have to use command line to do it

Environment Information

  • Operating System: MacOS Sonoma 14.6.1
  • Docker Version: Docker version 20.10.23, build 7155243
  • Node version: v18.12.1
  • Testcontainers version: 10.16.0
@nilPPanda nilPPanda changed the title .withEnvironment not working as expected .withEnvironment() not working as expected Dec 5, 2024
@cristianrgreco
Copy link
Collaborator

cristianrgreco commented Dec 5, 2024 via email

@nilPPanda
Copy link
Author

Okay, thanks, my bad copilot was suggesting the wrong format all the time

.withEnvironment({ MYSQL_HOSTNAME: sqlHostName }) is the correct line.

Thanks!

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

2 participants