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

Running python testcontainers on Mac Silicon M1 #186

Closed
jossefaz opened this issue Mar 20, 2022 · 5 comments
Closed

Running python testcontainers on Mac Silicon M1 #186

jossefaz opened this issue Mar 20, 2022 · 5 comments

Comments

@jossefaz
Copy link

jossefaz commented Mar 20, 2022

I am not sure if it is related to the docker installation on mac but I am not able to run testcontainers since I switched to Mac.
I got a timeout error on the self._connect() method
My code is petty straightforward :

def run_db():
    with MySqlContainer(f'mysql:5.7.17') as mysql:
        yield mysql

mysql = run_db()
conn_string = next(mysql).get_connection_url()
print(f"DB ready for connection at URL : {conn_string}")

I got this output :

Pulling image mysql:5.7.17
Container started: 9749203988
Waiting to be ready...

And then I got this traceback

---------------------------------------------------------------------------
TimeoutException                          Traceback (most recent call last)
/Users/user1/projects/my_project/poc1/poc1.ipynb Cell 6' in <cell line: 8>()
      6 mysql = run_db()
      7 # Connection string
----> 8 conn_string = next(mysql).get_connection_url()
      9 # Engine object
     10 engine = create_engine(conn_string)

/Users/user1/projects/my_project/poc1/poc1.ipynb Cell 4' in run_db()
     47 def run_db():
     48     """This function will run an instance of mysql db container and yield a testcontainer object
     49     This object will be used to CRUD data and profile the performance
     50     """
---> 51     with MySqlContainer(f'mysql:{MYSQL_VERSION}') as mysql:
     52         yield mysql

File ~/projects/my_project/venv/lib/python3.8/site-packages/testcontainers/core/container.py:64, in DockerContainer.__enter__(self)
     63 def __enter__(self):
---> 64     return self.start()

File ~/projects/my_project/venv/lib/python3.8/site-packages/testcontainers/core/generic.py:49, in DbContainer.start(self)
     47 self._configure()
     48 super().start()
---> 49 self._connect()
     50 return self

File ~/projects/my_project/venv/lib/python3.8/site-packages/testcontainers/core/waiting_utils.py:46, in wait_container_is_ready.<locals>.wrapper(wrapped, instance, args, kwargs)
     44         time.sleep(config.SLEEP_TIME)
     45         exception = e
---> 46 raise TimeoutException(
     47     """Wait time exceeded {0} sec.
     48         Method {1}, args {2} , kwargs {3}.
     49             Exception {4}""".format(config.MAX_TRIES,
     50                                     wrapped.__name__,
     51                                     args, kwargs, exception))

TimeoutException: Wait time exceeded 120 sec.
                Method _connect, args () , kwargs {}.
                    Exception 'NoneType' object is not subscriptable

The docker daemon is running and the output of docker ps command has no issue, but no container is running :

> docker ps                                                                                                       
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

EDIT

When trying to run mysql:5.7.17 manually : I got this error.

~ » docker run mysql:5.7.17
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
runtime: failed to create new OS thread (have 2 already; errno=22)
fatal error: newosproc

runtime stack:
runtime.throw(0x524da0, 0x9)
	/usr/local/go/src/runtime/panic.go:527 +0x90
runtime.newosproc(0xc82002a000, 0xc820039fc0)
	/usr/local/go/src/runtime/os1_linux.go:150 +0x1ab
runtime.newm(0x555ce8, 0x0)
	/usr/local/go/src/runtime/proc1.go:1105 +0x130
runtime.main.func1()
	/usr/local/go/src/runtime/proc.go:48 +0x2c
runtime.systemstack(0x5c4300)
	/usr/local/go/src/runtime/asm_amd64.s:262 +0x79
runtime.mstart()
	/usr/local/go/src/runtime/proc1.go:674

goroutine 1 [running]:
runtime.systemstack_switch()
	/usr/local/go/src/runtime/asm_amd64.s:216 fp=0xc820024770 sp=0xc820024768
runtime.main()
	/usr/local/go/src/runtime/proc.go:49 +0x62 fp=0xc8200247c0 sp=0xc820024770
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:1696 +0x1 fp=0xc8200247c8 sp=0xc8200247c0

So it seems to be architecture-related issue since the default image is built on amd64 and m1 is arm64...I will continue to search on this and will update

@jossefaz jossefaz changed the title Running testcontainers on Mac Silicon M1 Running python testcontainers on Mac Silicon M1 Mar 20, 2022
@jossefaz
Copy link
Author

Related thread : google/cadvisor#2763

@jossefaz
Copy link
Author

jossefaz commented Mar 20, 2022

I came across the option of specifying the platform :

docker pull --platform=linux/amd64 mysql

Which works
However, I did not manage to specify this option through the testcontainers API
I tried :

with MySqlContainer(platform='linux/amd64') as mysql:
    yield mysql

But I still got the timeout error.
However: I do see my container is now running by executing this code. But I still got the timeout error and testcontainers seems to not be able to retrieve the connection string from the running container :

~ » docker ps                                                                                                                       jazoulay@P6QMVFV7VH
CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS         PORTS                                NAMES
ccc42390b218   mysql:latest   "docker-entrypoint.s…"   4 minutes ago   Up 4 minutes   33060/tcp, 0.0.0.0:54094->3306/tcp   beautiful_mayer

@roman-baldaev
Copy link

roman-baldaev commented Mar 24, 2022

@jossefaz I have the same problem on my M1, but I think it's image specific.
Works fine with mysql/mysql-server image:

Pulling image mysql/mysql-server:latest
Container started: dede2cc85d
Waiting to be ready...
DB ready for connection at URL : mysql+pymysql://test:test@localhost:62925/test

@tillahoffmann
Copy link
Collaborator

Yes, mysql doesn't offer an arm image yet, as far as I'm aware. You can use the mariadb image instead and things should work as expected. See here for some more details: #136

@tillahoffmann
Copy link
Collaborator

Some of these issues should be fixed in 3.5.0 after merging #136. Feel free to reopen if M1-specific issues crop up again.

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