Running python testcontainers on Mac Silicon M1
See original GitHub issueI 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
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:5
Top Results From Across the Web
Using Apple Silicon (M1) as a cloud engineer, two months in
So I've been using my new M1-based MacBook Pro for a couple of months for a mix of development, email, and other things...
Read more >Mac m1 (apple silicon chip) and docker issues - Stack Overflow
For docker-compose, I have had many issues - intermittent SIG fault with deploying a java spring boot war on tomcat 9 and jdk...
Read more >Does docker work perfectly in Mac M1? - Reddit
Docker plays nice on M1 if your containers run code for arm64. If the code is amd64, Docker uses qemu emulation which works,...
Read more >How to Actually Deploy Docker Images Built on M1 Macs With ...
How to Actually Deploy Docker Images Built on M1 Macs With Apple Silicon. A guide to help you deploy cross-platform builds from your...
Read more >Java Development on an Apple M1 – A One Year Review
That's odd. It runs as snappy as ever on my 16G 2013 MacBook Pro.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I came across the option of specifying the platform :
Which works However, I did not manage to specify this option through the testcontainers API I tried :
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 :
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.